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년 전 | 2288 | |
| 329 |
prosper
|
20년 전 | 1919 | |
| 328 |
prosper
|
20년 전 | 1711 | |
| 327 | 20년 전 | 3778 | ||
| 326 | 20년 전 | 4865 | ||
| 325 |
hwatta
|
20년 전 | 2493 | |
| 324 |
|
20년 전 | 3150 | |
| 323 | 20년 전 | 5875 | ||
| 322 |
hwatta
|
20년 전 | 2860 | |
| 321 |
hwatta
|
20년 전 | 2332 | |
| 320 |
yesmoa
|
20년 전 | 4583 | |
| 319 | 20년 전 | 2696 | ||
| 318 | 20년 전 | 2244 | ||
| 317 |
kyodon
|
20년 전 | 2765 | |
| 316 | 20년 전 | 2588 | ||
| 315 |
|
20년 전 | 2890 | |
| 314 |
|
20년 전 | 3348 | |
| 313 |
|
20년 전 | 2654 | |
| 312 |
yesmoa
|
20년 전 | 4734 | |
| 311 | 20년 전 | 3288 | ||
| 310 |
홀로남은자
|
20년 전 | 4578 | |
| 309 | 20년 전 | 3014 | ||
| 308 | 20년 전 | 4145 | ||
| 307 | 20년 전 | 4382 | ||
| 306 | 20년 전 | 7044 | ||
| 305 | 20년 전 | 3877 | ||
| 304 | 20년 전 | 2776 | ||
| 303 |
크리스탈처럼
|
20년 전 | 4416 | |
| 302 | 20년 전 | 2217 | ||
| 301 |
|
20년 전 | 4334 | |
| 300 | 20년 전 | 3820 | ||
| 299 | 20년 전 | 2637 | ||
| 298 | 20년 전 | 4849 | ||
| 297 |
|
20년 전 | 2538 | |
| 296 | 20년 전 | 4545 | ||
| 295 | 20년 전 | 3577 | ||
| 294 | 20년 전 | 3598 | ||
| 293 | 20년 전 | 3827 | ||
| 292 | 20년 전 | 3222 | ||
| 291 |
yesmoa
|
20년 전 | 5962 | |
| 290 | 20년 전 | 2949 | ||
| 289 | 20년 전 | 5870 | ||
| 288 |
|
20년 전 | 2387 | |
| 287 |
|
20년 전 | 1819 | |
| 286 |
|
20년 전 | 2158 | |
| 285 |
|
20년 전 | 3551 | |
| 284 |
|
20년 전 | 2045 | |
| 283 |
|
20년 전 | 4406 | |
| 282 | 20년 전 | 3387 | ||
| 281 |
|
20년 전 | 2218 | |
| 280 |
|
20년 전 | 7822 | |
| 279 | 20년 전 | 5569 | ||
| 278 | 20년 전 | 3005 | ||
| 277 |
|
20년 전 | 5577 | |
| 276 | 20년 전 | 2368 | ||
| 275 | 20년 전 | 2625 | ||
| 274 | 20년 전 | 2405 | ||
| 273 | 20년 전 | 2240 | ||
| 272 | 20년 전 | 2169 | ||
| 271 | 20년 전 | 2636 | ||
| 270 | 20년 전 | 2676 | ||
| 269 | 20년 전 | 2518 | ||
| 268 | 20년 전 | 2704 | ||
| 267 | 20년 전 | 2386 | ||
| 266 | 20년 전 | 2576 | ||
| 265 | 20년 전 | 3519 | ||
| 264 |
|
20년 전 | 5382 | |
| 263 |
|
20년 전 | 3747 | |
| 262 | 20년 전 | 3204 | ||
| 261 |
허저비
|
20년 전 | 5948 | |
| 260 |
|
20년 전 | 5724 | |
| 259 | 20년 전 | 4151 | ||
| 258 | 20년 전 | 2385 | ||
| 257 | 20년 전 | 3207 | ||
| 256 | 20년 전 | 1920 | ||
| 255 | 20년 전 | 1590 | ||
| 254 | 20년 전 | 3160 | ||
| 253 | 20년 전 | 3555 | ||
| 252 | 20년 전 | 5140 | ||
| 251 | 20년 전 | 5831 | ||
| 250 | 20년 전 | 3689 | ||
| 249 | 20년 전 | 5036 | ||
| 248 | 20년 전 | 3305 | ||
| 247 | 20년 전 | 3659 | ||
| 246 |
|
20년 전 | 7968 | |
| 245 |
|
20년 전 | 5930 | |
| 244 | 20년 전 | 4498 | ||
| 243 |
|
20년 전 | 4078 | |
| 242 | 20년 전 | 2809 | ||
| 241 | 20년 전 | 2755 | ||
| 240 | 20년 전 | 2390 | ||
| 239 | 20년 전 | 1681 | ||
| 238 |
아우겐나이스
|
20년 전 | 2288 | |
| 237 |
email
|
20년 전 | 3702 | |
| 236 | 20년 전 | 4186 | ||
| 235 | 20년 전 | 10477 | ||
| 234 | 20년 전 | 5086 | ||
| 233 | 20년 전 | 3392 | ||
| 232 | 20년 전 | 3231 | ||
| 231 | 20년 전 | 3874 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기