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이 존재하게 됩니다.<
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 381 | ||
| 7929 | 9년 전 | 280 | ||
| 7928 | 9년 전 | 384 | ||
| 7927 | 9년 전 | 306 | ||
| 7926 | 9년 전 | 652 | ||
| 7925 | 9년 전 | 325 | ||
| 7924 | 9년 전 | 304 | ||
| 7923 | 9년 전 | 326 | ||
| 7922 | 9년 전 | 349 | ||
| 7921 | 9년 전 | 380 | ||
| 7920 | 9년 전 | 302 | ||
| 7919 | 9년 전 | 319 | ||
| 7918 | 9년 전 | 479 | ||
| 7917 | 9년 전 | 319 | ||
| 7916 | 9년 전 | 386 | ||
| 7915 | 9년 전 | 379 | ||
| 7914 | 9년 전 | 389 | ||
| 7913 | 9년 전 | 516 | ||
| 7912 | 9년 전 | 389 | ||
| 7911 | 9년 전 | 335 | ||
| 7910 | 9년 전 | 375 | ||
| 7909 | 9년 전 | 478 | ||
| 7908 | 9년 전 | 377 | ||
| 7907 | 9년 전 | 335 | ||
| 7906 | 9년 전 | 349 | ||
| 7905 | 9년 전 | 339 | ||
| 7904 | 9년 전 | 310 | ||
| 7903 | 9년 전 | 312 | ||
| 7902 | 9년 전 | 523 | ||
| 7901 |
|
9년 전 | 721 | |
| 7900 | 9년 전 | 551 | ||
| 7899 | 9년 전 | 353 | ||
| 7898 | 9년 전 | 348 | ||
| 7897 | 9년 전 | 305 | ||
| 7896 | 9년 전 | 334 | ||
| 7895 | 9년 전 | 437 | ||
| 7894 | 9년 전 | 359 | ||
| 7893 | 9년 전 | 298 | ||
| 7892 | 9년 전 | 346 | ||
| 7891 | 9년 전 | 728 | ||
| 7890 | 9년 전 | 1181 | ||
| 7889 | 9년 전 | 738 | ||
| 7888 |
limsy1987
|
9년 전 | 532 | |
| 7887 | 9년 전 | 516 | ||
| 7886 | 9년 전 | 402 | ||
| 7885 | 9년 전 | 376 | ||
| 7884 | 9년 전 | 380 | ||
| 7883 | 9년 전 | 369 | ||
| 7882 | 9년 전 | 387 | ||
| 7881 | 9년 전 | 407 | ||
| 7880 | 9년 전 | 532 | ||
| 7879 | 9년 전 | 427 | ||
| 7878 | 9년 전 | 1172 | ||
| 7877 | 9년 전 | 721 | ||
| 7876 | 9년 전 | 448 | ||
| 7875 | 9년 전 | 526 | ||
| 7874 |
|
9년 전 | 786 | |
| 7873 | 9년 전 | 486 | ||
| 7872 | 9년 전 | 630 | ||
| 7871 | 9년 전 | 454 | ||
| 7870 | 9년 전 | 585 | ||
| 7869 | 9년 전 | 398 | ||
| 7868 | 9년 전 | 397 | ||
| 7867 | 9년 전 | 393 | ||
| 7866 | 9년 전 | 459 | ||
| 7865 | 9년 전 | 415 | ||
| 7864 | 9년 전 | 477 | ||
| 7863 | 9년 전 | 467 | ||
| 7862 | 9년 전 | 443 | ||
| 7861 | 9년 전 | 601 | ||
| 7860 | 9년 전 | 599 | ||
| 7859 | 9년 전 | 376 | ||
| 7858 | 9년 전 | 681 | ||
| 7857 | 9년 전 | 1035 | ||
| 7856 | 9년 전 | 493 | ||
| 7855 | 9년 전 | 715 | ||
| 7854 | 9년 전 | 703 | ||
| 7853 | 9년 전 | 557 | ||
| 7852 | 9년 전 | 475 | ||
| 7851 | 9년 전 | 460 | ||
| 7850 | 9년 전 | 558 | ||
| 7849 | 9년 전 | 327 | ||
| 7848 | 9년 전 | 379 | ||
| 7847 | 9년 전 | 600 | ||
| 7846 | 9년 전 | 424 | ||
| 7845 | 9년 전 | 379 | ||
| 7844 | 9년 전 | 372 | ||
| 7843 | 9년 전 | 383 | ||
| 7842 | 9년 전 | 372 | ||
| 7841 | 9년 전 | 360 | ||
| 7840 | 9년 전 | 368 | ||
| 7839 | 9년 전 | 408 | ||
| 7838 | 9년 전 | 488 | ||
| 7837 | 9년 전 | 333 | ||
| 7836 | 9년 전 | 371 | ||
| 7835 | 9년 전 | 450 | ||
| 7834 |
|
9년 전 | 1176 | |
| 7833 | 9년 전 | 388 | ||
| 7832 | 9년 전 | 390 | ||
| 7831 | 9년 전 | 522 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기