crontab 에 등록해놓고 예외시킨 디비를 제외한 모든 디비를
백업받는 스크립트 입니다.
#!/usr/local/php/bin/php -q
<?php
@set_time_limit (0);
@ini_set ("memory_limit", "20M");
$save_dir = '절대경로/dbbackup';//저장할 장소, 절대경로/dbbackup 퍼미션은 777로 주세요
$dateYmdH = date("YmdH");
$break_dbname = '예외디비명1|예외디비명2';//디비백업에 열외시킬 디비들
$deldate = 7;//삭제일 현재는 7일지난 데이터는 삭제
echo "[백업한 sql] \n\n";
mysql_connect('디비접속호스트', 'root', '디비루트패스워드');
$db_list = mysql_list_dbs();
$i = 0;
$cnt = mysql_num_rows($db_list);
while ($i < $cnt) {
$dbname = mysql_db_name($db_list, $i);
$i++;
if (!empty($dbname)) {
if (!empty($break_dbname) && preg_match("`^(" . $break_dbname . ")$`i", $dbname))
continue;
echo "[ " . $dbname . "]\n";
exec('/usr/local/mysql/bin/mysqldump -h디비접속호스트 -uroot -p루트패스워드 ' . $dbname . ' > ' . $save_dir . '/' . $dbname . $dateYmdH . '.sql');
}
}
echo "\n\n[삭제한 sql] \n\n";
$d = dir($save_dir);
while (false !== ($entry = $d->read())) {
if (!preg_match("|^\.|", $entry)) {
if (!empty($break_dbname) && preg_match("`^(" . $break_dbname . ")[0-9]{0,10}\.sql$`i", $entry))
continue;
$temp_file = $save_dir . '/' . $entry;
$temp_mtime = @filemtime($temp_file);
$temp_during = time() - $temp_mtime;
if ($temp_during > (60 * 60 * 24 * $deldate)){
$temp_cnt++;
@unlink($temp_file);
echo "[" . $temp_file . "]\n";
}
}
}
$d->close();
exit;
?>
소스중에 #!/usr/local/php/bin/php -q 이부분은 자신의 php환경에 맞추어야 합니다.
이스크립트는 mysql 루트 권한이 있어야 사용가능합니다.
위 소스를 파일로 서버에 저장한 후 퍼미션을 755 로 주시기 바랍니다.
크론탭에 등록하는 방법
# crontab -e
30 */6 * * * /home/conf/cronwork/dbbackup.php #6시간에 한번씩
라고 넣고 저장
6시간에 한번씩, 해당 시간의 30분에 실행됩니다.
위의 세팅 그대로 사용하면
하루에 4번, 7일동안 보관하므로
하나의 디비에 대해 총 28개의 백업sql이 존재하게 됩니다.<
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 330 |
prosper
|
20년 전 | 2244 | |
| 329 |
prosper
|
20년 전 | 1857 | |
| 328 |
prosper
|
20년 전 | 1668 | |
| 327 | 20년 전 | 3745 | ||
| 326 | 20년 전 | 4824 | ||
| 325 |
hwatta
|
20년 전 | 2452 | |
| 324 |
|
20년 전 | 3122 | |
| 323 | 20년 전 | 5832 | ||
| 322 |
hwatta
|
20년 전 | 2822 | |
| 321 |
hwatta
|
20년 전 | 2300 | |
| 320 |
yesmoa
|
20년 전 | 4558 | |
| 319 | 20년 전 | 2656 | ||
| 318 | 20년 전 | 2225 | ||
| 317 |
kyodon
|
20년 전 | 2752 | |
| 316 | 20년 전 | 2559 | ||
| 315 |
|
20년 전 | 2869 | |
| 314 |
|
20년 전 | 3313 | |
| 313 |
|
20년 전 | 2625 | |
| 312 |
yesmoa
|
20년 전 | 4700 | |
| 311 | 20년 전 | 3234 | ||
| 310 |
홀로남은자
|
20년 전 | 4540 | |
| 309 | 20년 전 | 2996 | ||
| 308 | 20년 전 | 4108 | ||
| 307 | 20년 전 | 4341 | ||
| 306 | 20년 전 | 7013 | ||
| 305 | 20년 전 | 3854 | ||
| 304 | 20년 전 | 2745 | ||
| 303 |
크리스탈처럼
|
20년 전 | 4380 | |
| 302 | 20년 전 | 2191 | ||
| 301 |
|
20년 전 | 4311 | |
| 300 | 20년 전 | 3772 | ||
| 299 | 20년 전 | 2578 | ||
| 298 | 20년 전 | 4806 | ||
| 297 |
|
20년 전 | 2511 | |
| 296 | 20년 전 | 4505 | ||
| 295 | 20년 전 | 3552 | ||
| 294 | 20년 전 | 3577 | ||
| 293 | 20년 전 | 3806 | ||
| 292 | 20년 전 | 3191 | ||
| 291 |
yesmoa
|
20년 전 | 5908 | |
| 290 | 20년 전 | 2928 | ||
| 289 | 20년 전 | 5831 | ||
| 288 |
|
20년 전 | 2355 | |
| 287 |
|
20년 전 | 1772 | |
| 286 |
|
20년 전 | 2127 | |
| 285 |
|
20년 전 | 3525 | |
| 284 |
|
20년 전 | 2023 | |
| 283 |
|
20년 전 | 4387 | |
| 282 | 20년 전 | 3373 | ||
| 281 |
|
20년 전 | 2193 | |
| 280 |
|
20년 전 | 7789 | |
| 279 | 20년 전 | 5525 | ||
| 278 | 20년 전 | 2976 | ||
| 277 |
|
20년 전 | 5560 | |
| 276 | 20년 전 | 2347 | ||
| 275 | 20년 전 | 2588 | ||
| 274 | 20년 전 | 2353 | ||
| 273 | 20년 전 | 2201 | ||
| 272 | 20년 전 | 2128 | ||
| 271 | 20년 전 | 2590 | ||
| 270 | 20년 전 | 2597 | ||
| 269 | 20년 전 | 2465 | ||
| 268 | 20년 전 | 2666 | ||
| 267 | 20년 전 | 2349 | ||
| 266 | 20년 전 | 2556 | ||
| 265 | 20년 전 | 3484 | ||
| 264 |
|
20년 전 | 5343 | |
| 263 |
|
20년 전 | 3706 | |
| 262 | 20년 전 | 3159 | ||
| 261 |
허저비
|
20년 전 | 5910 | |
| 260 |
|
20년 전 | 5705 | |
| 259 | 20년 전 | 4125 | ||
| 258 | 20년 전 | 2366 | ||
| 257 | 20년 전 | 3172 | ||
| 256 | 20년 전 | 1891 | ||
| 255 | 20년 전 | 1552 | ||
| 254 | 20년 전 | 3127 | ||
| 253 | 20년 전 | 3535 | ||
| 252 | 20년 전 | 5099 | ||
| 251 | 20년 전 | 5795 | ||
| 250 | 20년 전 | 3663 | ||
| 249 | 20년 전 | 5001 | ||
| 248 | 20년 전 | 3272 | ||
| 247 | 20년 전 | 3622 | ||
| 246 |
|
20년 전 | 7934 | |
| 245 |
|
20년 전 | 5888 | |
| 244 | 20년 전 | 4471 | ||
| 243 |
|
20년 전 | 4030 | |
| 242 | 20년 전 | 2758 | ||
| 241 | 20년 전 | 2702 | ||
| 240 | 20년 전 | 2343 | ||
| 239 | 20년 전 | 1639 | ||
| 238 |
아우겐나이스
|
20년 전 | 2245 | |
| 237 |
email
|
20년 전 | 3671 | |
| 236 | 20년 전 | 4130 | ||
| 235 | 20년 전 | 10451 | ||
| 234 | 20년 전 | 5046 | ||
| 233 | 20년 전 | 3358 | ||
| 232 | 20년 전 | 3183 | ||
| 231 | 20년 전 | 3821 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기