VPSã§é㶠-ãã®ï¼ï¼ ï¼darã¨mysqldumpãã¤ãã£ã¦ãµã¼ãã¼ã®æ次ãã«ããã¯ã¢ããã¨æ¥æ¬¡å·®åããã¯ã¢ãããåãï¼åç·¨ï¼VPSé¯å´ã§ãã³ãä½æã®å·»ï¼
ã¿ãªãã¾ãä¹
ãã¶ãã§ãã
ã©ããã®ã¬ã³ãµãå±ããã¼ã¿ã¼ããµã£é£ã°ããã¨èãã¾ããã
æãã§ããã¼ãé¯å±ãªãã¦ä¿¡ç¨ã§ãã¾ãããã¼ãèªè¡ãå¿
è¦ã§ããã¼ã
ã¨ããããã§å®é¯ã»VPSé¯ã使ã人ã
ï¼ã«éããçã
æ§ï¼ã¯èªåã®æå
ã«å¿
ãæ¥æ¬¡ããã¯ã¢ãããæã£ã¦ããã¾ãããã
ï¼åºæ¥ãã°éé»ããªãç°å¢ãç©ççã«é¢ããç°å¢ã«ã³ãã¼âå¥ã®å ´æã«æ°ä¸ä»£åã¾ã§å®æçã«ä¿åããã¦ããã¾ããããHDDãªãã¦ã¿ãã¿ãããªããã ãã
ç§ã¯æ±äº¬å¤§éªã¢ã¡ãªã«è¥¿æµ·å²¸ã«åæ£ããã¦ãã¾ãã
ãã¨æéè¦ãã¼ã¿ã®æ°GBã¯ãã¹ã¯ã¼ãä»ãå§ç¸®ï¼æå·åãã£ã¹ã¯ã¤ã¡ã¼ã¸ã«ä¿åãããã¤ãmicrosdã«å
¥ãã¦å¿µã«ã¯å¿µãå
¥ãã¦ãã¾ãã
èªè¡ãéè¦ãä»äººã®å®å ¨å®£è¨ã¯ä¿¡ãããªãä¿¡ããããã®ã¯èªåã ããï¼å²ã¨ãã¸ï¼
ããã¾é¢ä¿ãªããã©HDDä¸èª¿æã¯fsckæããåã«ddrescueã§ãã£ã¹ã¯ã¤ã¡ã¼ã¸ã®ã¯ãã¼ã³ãä½ã£ãããã¦ãã£ã¹ã¯ã¤ã¡ã¼ã¸å´ãæä½ãã¾ããããâ¦
ã¦ã«ãã¦ã¼ã¶ã¼åãããã¯ã¢ããã¹ã¯ãªããå ¬é
ãã¼ã¿æµåºãæããã©ãã¼ã¿æ¹æ¶ããã®ãããæããã¨ããããã§ä»æ¥ã¯ç§ã®ä½¿ã£ã¦ããVPSé¯å ãã¡ã¤ã«ããã¯ã¢ããã¹ã¯ãªãããå ¬éãã¦ããã¾ãã
ãã©ã³ã¶ã¯ã·ã§ã³å¦ççããªããªãã£ã¦ããé¯ã¯å¯¾è±¡ã§ã¯ããã¾ããããæ£ããéç¨ãããã¨ã§å ¨ãã¼ã¿ãã¹ã復æ§ä¸å¯ï¼¼(^o^)ï¼ï½µï¾ï¾ãé¿ãããã¨ã¯åºæ¥ãã¨æãã¾ããï¼ã ãããè¯ãæãã«æ»ããä½ãå®å ¨å®ç§ã§ã¯ãªãããã©ã³ã¶ã¯ã·ã§ã³ãã¼ã¿ã¯ã©ã£ãã«æ¶ãããããã¨ããæããï¼
ï¼ã¤ãã§ã«/etc以ä¸ã¨ãã¯mercurialãå°å ¥ãã¦å±¥æ´ç®¡çããã¦ããã¾ããããé¯å±ãä¿¡ããæ´æ°å·®åããã¤ã§ãåããããã«ãã¦ãããã¨ãéè¦ã ã¨æãã¾ããï¼
ã¾ããã¼ã¿ã¼ãã¹ãï¼ããã¯ã¢ãããã¼ã¨ã§çµããä¼ç¤¾ãªãã¦æãç«ã£ã¦ãã»ããå¥è·¡ã§ãããï¼ãã¼ã«ã·ããã§é»ç£æ³¢ãäºã å°çã®å±æ©ã¬ã¼ã¨ãããããã®ã¯å¥ãããããªã£ããç´ã¨ãç³çã¨ãå£é ä¼æ¿ããæ®ããªãããï¼
ã注æï¼
ãã®ã¹ã¯ãªããã®éç¨ãã¹ã»å°æ¥ã®ããã°ã©ã æ§é ã®å¤åãªã©ã§ããã¯ã¢ããã¹ã¯ãªãããåãããã¼ã¿ãé£ã°ãã¦ãç§ã¯ä¸å責任ãæã¡ã¾ããã
å·®åããã¯ã¢ãããè¨ãã¦ãã£ã¹ã¯ãã«ã§ãµã¼ãã¼ãåæ¢ãã¦ãç¥ãã¾ããã
å®æçã«ããã¯ã¢ãããåãã¦ãããã®ç¢ºèªã»å¾©æ§åºæ¥ããã®ç¢ºèªã»ãã£ã¹ã¯å®¹éã足ãã¦ãããã®ç¢ºèªçã¯ããªãã®ä»äºã§ãã
ããã¾ã§ãææ³ã®ç´¹ä»ã§ãã®ã§èªå·±è²¬ä»»ã§ãããã«æ¸ãã¦ãããã¨ãéµåã¿ã«ããªãã§ãã ããã
åææ¡ä»¶
åºæ¬çãªã¤ã³ã¹ãã¼ã«ã«ã¤ãã¦ã¯çç¥ãã¾ããã¾ããæå ï¼èªå® çï¼ã«ãã¼ã¿ã転éããããã¯ã¢ããç¨ã¦ã¼ã¶ã¼ã¯ãã¹ãã¬ã¼ãºç¡ãã®å ¬ééµèªè¨¼ã§sshæ¥ç¶ãã¾ããããã¡ãã®èª¬æãçç¥ãã¾ããï¼ããããªãå ´åã¯å¯¾è±¡å¤ã§ãã®ã§ä»¥ä¸ã®ã¹ã¯ãªããã¯ä½¿ããªãã§ãã ãããï¼
- ä¸æ¥ä¸åã®ç§æçãªããã¯ã¢ããã§è¯ããï¼ãªã¢ã«ã¿ã¤ã ã«ããã¯ã¢ãããããã»ãã©ã³ã¶ã¯ã·ã§ã³ããªããªãªç°å¢ã¯å¯¾è±¡å¤ãé²è¦§ä¸»ä½ã®PHP-MySQL製CMSãå®ç©VPSã«çªã£è¾¼ãã ç°å¢ãæ³å®ãï¼
- Linuxã§ããã(Ubuntu 10.04LTS)
- sh(bash)ãåãã
- ã³ãã³ãã©ã¤ã³ã§PHPãåããï¼å¼ã³åºãé¨åãPHPã§ä½ã£ã俺俺ã¹ã¯ãªãããªã®ã§ãï¼
- dar(ãã£ã¹ã¯ã¢ã¼ã«ã¤ã)ãã¤ã³ã¹ãã¼ã«ãã¦ããã( aptitude install dar )
- 使ã£ã¦ããDBã¯mysqlã§ããã(postgresql対å¿çããããã©ä»åã¯ç°¡åã®ããã«çç¥ï¼
- VPSãµã¼ãã¼ã®ç°å¢æ§ç¯ä½èªåã§åºæ¥ãã
- ãã¼ã«ã«ââVPSãµã¼ãã¼éã§å ¬ééµèªè¨¼ãã¤ãã¼ãã¹ã¯ã¼ãã§æ¥ç¶ã§ããããã¯ã¢ãããã¡ã¤ã«è»¢éå°ç¨ã¦ã¼ã¶ã¼ãä½æåºæ¥ãã
- æå ï¼ãã¼ã«ã«ï¼ã¾ãã¯å¥ä¼ç¤¾ã«Linuxé¯ããã£ã¦rsyncãåºæ¥ãã
- ä¸ã¶æåã®å·®åããã¯ã¢ãããã¡ã¤ã«ãä¿åå¯è½ãªååãªãã£ã¹ã¯ç©ºã容éãVPSå´ããã¼ã«ã«å´åæ¹ã«åå¨ããã
ã¨ããè¦ã¯VPSã¨ãå°ç¨é¯ã®ç°å¢ã§ããå ±æã¬ã³ãµãã¯å¯¾è±¡å¤ã§ãã
dar (http://dar.linux.free.fr/) ã®æ¦è¦ã«ã¤ãã¦ã®èª¬æãçãã¾ãããdar ããã¯ã¢ãããã§ã°ã°ã£ã¦å 人ã®è§£èª¬ãã¼ã¸ãè¦ã¦ãã ããã
darã®ä½ãå¬ãããç°¡åã«ããã¨ã
- ãã«ããã¯ã¢ããã1ãã¡ã¤ã«ã«å§ç¸®ãã¦ä¿åã§ããã
- ãã«ããã¯ã¢ãããå ã«å·®åããã¯ã¢ãããä½æã§ããã®ã§æ¥æ¬¡ã§ã¯å·®åã®ã¿ä½æãã¦è² è·ãæ¸ãããã
- ããã¯ã¢ãã対象å¤ã»å§ç¸®å¯¾è±¡å¤çã®ç´°ããªå¶å¾¡ãå¯è½ã§ããã
ã£ã¦ãã¨ã§ãã
æ¦è¦
ãã£ã¦ããã¨ã¯åç´ã§å³ã§æ¸ãã¨ãããªæããVPSé¯å´ã§æ¯æ¥ï¼æä¸åãã«ããã¯ã¢ãããæ¯æ¥å·®åããã¯ã¢ããï¼ã®ããã¯ã¢ãããã¡ã¤ã«ãçæãã¦ä¿åãã¦ãã
â
ä¿åãããã¡ã¤ã«ãæå ã®ãµã¼ãã¼å´èµ·åã§rsyncã§åå¾ãããï¼æå ã®ãµã¼ãã¼èµ·åãªã®ã§ãæå å´ãåºå®IPãããªãã¦ãOKï¼
- crontabèµ·åã®PHPã¹ã¯ãªããããdarã使ã£ã¦VPSãµã¼ãã¼å ãã¡ã¤ã«ã®ããã¯ã¢ãã
- mysqldumpã使ã£ã¦DBã®ããã¯ã¢ãã
- crontabèµ·åã®rsyncã§æå å´ãµã¼ãã¼ã¨ããã¯ã¢ãããã¡ã¤ã«ã®åæ
ã¦ãªãããã§ãã
ãããªæãã§æ¯æ1æ¥ã«ãã¡ã¤ã«ã®ãã«ããã¯ã¢ããããã以å¤ã®æ¯æ¥ã¯ãã«ããã¯ã¢ããããã®å·®åããã¯ã¢ãããã¦ãã¾ãã
å·®åããã¯ã¢ããã¯å¤åããªããã°æ®ã©å®¹éãé£ãã¾ããã
ã¹ã¯ãªãã
以ä¸ã«ã¹ã¯ãªãããè²¼ã£ã¦ããã¾ããæ¬æ¥ã¯VPSãµã¼ãã¼å´ãæå å´ãµã¼ãã¼ã«rsyncããé¨åã«ã¤ãã¦ã¯ä¸ç·¨ã»å¾ç·¨ã§ã
ãã£ã¹ã¯ã®ããã¯ã¢ããèªä½ã¯ã«ã¼ãã¦ã¼ã¶ã¼ã«å®è¡ããã¾ãã
ï¼ä¸è¬ã¦ã¼ã¶ã¼ã®èªããé åã®ã¿ããã¯ã¢ããã§ãããªã好ãã«ãã¦ãã ãããï¼
ã¹ã¯ãªãã1ï¼VPSãµã¼ãã¼å´ãrootã¦ã¼ã¶ã¼ã®crontab -e
# m h dom mon dow command 10 03 * * * /root/bin/mysql-backup.sh >/dev/null 2>&1 40 03 1 * * /root/bin/dar_backup.php -f > /backup/local/dar.log 2>&1 40 03 2-31 * * /root/bin/dar_backup.php -d > /backup/local/dar.log 2>&1
mysql-backup.shãdar_backup.php ãããã¯ã¢ããã¹ã¯ãªããã§ãã/root/bin/ã«è¨ç½®ãã¦ãã¾ãã
- æ¯æ¥ã®mysql-backup.shã¯mysqlã®ãã³ããã¡ã¤ã«ã®ããã¯ã¢ããã
- æ¯æ1æ¥ã¯darã®ãã«ããã¯ã¢ããã
- æ¯æ2æ¥ã31æ¥ã¯darã®å·®åããã¯ã¢ãããï¼ãã«ããã¯ã¢ããã¨ã®å·®åãªã®ã§æ¯æ¥ã®å·®ã大ããã¨ãã£ã¹ã¯ãã«ã«ãªãå±éºãã注æï¼
ããããªã£ã¦ãã¾ãã
ã¹ã¯ãªãã2ï¼VPSãµã¼ãã¼å´ãããã¯ã¢ãããã¡ã¤ã«ä¿åãã£ã¬ã¯ããªã®ä½æã¹ã¯ãªãã
ãã®ã¹ã¯ãªããã¯ããã¯ã¢ããç°å¢æ§ç¯æã®ååã®ã¿ä½¿ãã¾ãã
/root/bin/mkbackupdir.sh
#!/bin/sh mkdir -p /backup/local/dailybk mkdir -p /backup/local/dar_file mkdir -p /backup/local/mysql mkdir -p /backup/local/psql chmod 600 /backup chown -R backupusr:users /backup chmod 600 /backup/local/dailybk chmod 600 /backup/local/dar_file chmod 600 /backup/local/mysql chmod 600 /backup/local/psql
backupusrã¯ãVPSãµã¼ãã¼å´ã®ããã¯ã¢ãããã¡ã¤ã«rsyncç¨ã®å°ç¨ã¦ã¼ã¶ã¼ã§ããä»»æã®ã¦ã¼ã¶ã¼ãä½ã£ã¦ãã ããã
ããã¯ã¢ãããããã¡ã¤ã«ã¯root権éã¦ã¼ã¶ã¼ã¨backupusrã®ã¿ãèªã¿åãå¯è½ã§ãã
/backupã¨ãã¦ãã¾ããããã¯æããã¯ã¢ããç¨ãã¼ãã£ã·ã§ã³ãåãã¦ããåæ®ã§ããç¹ã«æ·±ãæå³ã¯ããã¾ããã
/backup/local/ãªã®ã¯ç¸äºããã¯ã¢ãããããã¨ãã« /backup/remote/ã¨ã /bakup/ç¸æé¯å/ ã¨ãã®æ§æã«ããå ´åãããããã§ãã
ã¹ã¯ãªãã3ï¼VPSãµã¼ãã¼å´ãDBæ¯ã®mysqldumpå©ç¨ã®ãã³ããã¡ã¤ã«çæã¹ã¯ãªãã
ï¼2012/06/25 VPSå´ã«ã3æ¥åä¿åããå ´åã®ä¾ãã³ã¡ã³ãã¢ã¦ããã¦è¿½å ï¼$BACKIDIRãæ¯åãã£ã¬ã¯ããªåé¤ããã®ãããã¦$BACKIDIRå
ãã¡ã¤ã«åé¤ã«å¤æ´ï¼
/root/bin/mysql-backup.sh (è¦chmod 700)
#!/bin/bash PATH=/usr/local/sbin:/usr/bin:/bin NOW=`date +%Y%m%d` # ããã¯ã¢ããå ãã£ã¬ã¯ã㪠BACKDIR=/backup/local/mysql #空ç½ä¸å¯æ³¨æ DAILY_BACKDIR=/backup/local/dailybk #空ç½ä¸å¯æ³¨æ # MySQLrootãã¹ã¯ã¼ã ROOTPASS=hogehgoerootpass # backupï¼è»¢éç¨ï¼ã®ã¦ã¼ã¶ã¼ BACKUPUSR=backupusr # ããã¯ã¢ããå ãã£ã¬ã¯ããªå åæ¥ãã³ãåé¤ find $BACKIDIR -type f -name "*.dump.sql.gz"|xargs rm -f chmod -R 600 $BACKDIR chmod -R 600 $DAILY_BACKDIR touch $BACKDIR touch $DAILY_BACKDIR # ãã¼ã¿ãã¼ã¹ååå¾ DBLIST=`ls -p /var/lib/mysql | grep / | tr -d /` # ãã¼ã¿ãã¼ã¹ãã¨ã«ããã¯ã¢ãã for dbname in $DBLIST do nice -n 19 mysqldump -uroot -p$ROOTPASS --default-character-set=binary $dbname | nice -n 19 gzip > $BACKDIR/$dbname.dump.sql.gz; chmod 600 $BACKDIR/$dbname.dump.sql.gz; done #dumpãã¡ã¤ã«ãå§ç¸®ãã¦ä¿åãVPSå´ã«ã3æ¥åä¿åããå ´åã¯ä¸äºè¡ã®æ¹ãæå¹ã« nice -n 19 tar zcf $DAILY_BACKDIR/mysql_dailybk_mysqldump.tar.gz $BACKDIR #find $DAILY_BACKDIR -type f -mtime +2 -name "mysql*dailybk*.gz" |xargs rm -f #nice -n 19 tar zcf $DAILY_BACKDIR/mysql_dailybk_mysqldump_$NOW.tar.gz $BACKDIR chmod 600 $DAILY_BACKDIR/mysql*dailybk*.gz chown $BACKUPUSR:users $DAILY_BACKDIR/mysql*dailybk*.gz chown -R $BACKUPUSR:users $BACKDIR chown -R $BACKUPUSR:users $DAILY_BACKDIR
ROOTPASS(mysqlã®rootã¦ã¼ã¶ã¼ã®ãã¹ã¯ã¼ãï¼ãBACKUPUSRã¯é©å®å¤æ´ãã¦ãã ããã
ï¼mysqlã®DBå
ããDBåãåå¾ãã/var/lib/mysqlã®ãã£ã¬ã¯ããªããDBåãåå¾ãã¦ãã®ã§ä¹±æ´ã§ããåãã®ã§OKï¼
ããã§ã¯
- mysqldumpãããããåããªãããã¼ã¿ãã¼ã¹æ¯ã«ãã³ããã¡ã¤ã«ãä½æãã¦
- /backup/local/mysql/以ä¸ã«ææ°ãã³ããDBæ¯ã«ä¿åãã¦
- ã¤ãã§ã«$DAILY_BACKDIR/mysql_dailybk_mysqldump.tar.gz ã«åºãã¦ä¿åã
- èªã¿åã権éã¨ææè ã®å¤æ´ããã¦ãã¾ãã
ã¾ã次åãããèµ·åæã«ååããããã¡ã¤ã«ã®ãã³ãã¯/backup/local/mysql/ãã¾ããã¨rm -rf ãã¦ãã¾ãã
ã¹ã¯ãªãã4ï¼VPSãµã¼ãã¼å´ãdarã®ãã£ã¹ã¯ã¢ã¼ã«ã¤ãçæã¹ã¯ãªãã
/root/bin/dar_backup.php (è¦chmod 700)
#!/usr/bin/php -q <?php if (!isset($argv[1])){ echo "å¼æ°ãããã¾ãã -f or -d \n"; exit; } $ptn = $argv[1]; //backupãã¡ã¤ã«ã®èªVPSå è¨ç½®å ´æ define("log_path", "/backup/local/darbk.log"); define("bk_base", "/backup/local/dar_file"); /** * #VPSãµã¼ãã¼å´ããã®rsyncã¯è¡ããããã¼ã«ã«å´ããã®rsyncã«èµ·åæ¹æ³ãå¤æ´ããããå»æ¢ * define("sync_use",false) ; * define("sync_to","remote-back@example.com:/backup/remote/mysvname/") ; */ define("nowtime", time()); // dar ã®èµ·åãªãã·ã§ã³ã-Z以ä¸ã¯è² è·åæ¸ã®ããäºéã«å§ç¸®ããªããã¡ã¤ã«ãï¼http://dar.linux.free.fr/doc/man/dar.html $option = <<<___END___ -v -D -m 256 -y9 -Z "*.gz" -Z "*.Z" -Z "*.bz2" -Z "*.tgz" -Z "*.lzh" -Z "*.zip" -Z "*.jpg" -Z "*.JPG" -Z "*.jpeg" -Z "*.JPEG" -Z "*.png" -Z "*.PNG" -Z "*.gif" -Z "*.GIF" -Z "*.mpg" -Z "*.MPG" -Z "*.mpeg" -Z "*.MPEG" -Z "*.mp3" -Z "*.rm" -Z "*.jar" -Z "*.exe" -Z "*.EXE" -Z "*.msi" -Z "*.MSI" -Z "*.divx" -Z "*.flv" -Z "*.mov" -Z "*.wma" -Z "*.iso" -Z "*.img" -Z "*.ISO" -Z "*.IMG" -Z "*.swf" -Z "*.slc" -Z "*.ts" -Z "*.class" ___END___; $option = preg_replace("/\r/iu", " ", $option); $option = preg_replace("/\n/iu", " ", $option); define("option_param", $option); // ããã¯ã¢ãã対象ã®ãã£ã¬ã¯ããª(/ç´ä¸ã®ãã£ã¬ã¯ããªåã®ã¿æå®å¯è½ï¼ãé¤å¤ãã£ã¬ã¯ããªã¯"p"=>array("dir1","dir2",⦠),ã§æå®ã $bk_arr = array( // array("t"=>"backup"), array("t" => "bin"), array("t" => "boot"), array("t" => "dev"), array("t" => "etc"), array("t" => "home"), array("t" => "lib"), array("t" => "lost+found"), array("t" => "media"), array("t" => "misc"), array("t" => "mnt"), // array("t"=>"net"), array("t" => "opt"), // array("t"=>"proc"), array("t" => "root"), array("t" => "sbin"), array("t" => "selinux"), array("t" => "srv"), // array("t"=>"sys"), array("t" => "tmp"), array("t" => "usr", "p" => array("local/delegate")), // ããã§ã¯/usr/local/delegeteã¯é¤å¤ãã¦ãã array("t" => "var", "p" => array("cache", "spool/squid", "log", "named/chroot/proc")), // ããã§ã¯ /var/cache, /var/spool/squid, /var/logçãé¤å¤ãã¦ããããã£ã¹ã¯ç©ºã容éã®é¢ä¿ãã/var/logã¯rsyncãã¦ãã®ã§é¤å¤ ); if ("-f" === $ptn || "-d" === $ptn){ $msg = date("Y-m-d H:i:s", nowtime) . " Backup START\n"; echo $msg ; switch ($ptn){ case "-f":// æ次ç¨ãã«ããã¯ã¢ãã $pre_cmd = get_cmd_list("full", null, true); $cmd_list = get_cmd_list("full", $bk_arr); break; case "-d":// æ¥æ¬¡ç¨å·®åããã¯ã¢ãã $pre_cmd = get_cmd_list("diff", null, true); $cmd_list = get_cmd_list("diff", $bk_arr); break; default: $cmd_list = array(); break; } foreach($pre_cmd as $k => $v){ echo $v . "\n"; system($v); //32æ¥ä»¥ä¸æã®darãã¡ã¤ã«ã®åé¤ } foreach($cmd_list as $k => $v){ echo $v . "\n"; system($v); //darããã¯ã¢ããã®é 次å®è¡ } $msg = date("Y-m-d H:i:s", time()) . " Backup END \n"; echo $msg ; } /** * #VPSãµã¼ãã¼å´ããã®rsyncã¯è¡ããããã¼ã«ã«å´ããã®rsyncã«èµ·åæ¹æ³ãå¤æ´ããããå»æ¢ * if(sync_use){ * if("-f"===$ptn||"-d"===$ptn||"-r"===$ptn){ * $msg = date("Y-m-d H:i:s",time()). " Rsync START \n"; * echo $msg ; * $cmd = "rsync -auvz -e ssh --delete ".bk_base." ".sync_to." " ; * system($cmd); * $msg = date("Y-m-d H:i:s",time()). " Rsync END \n"; * echo $msg ; * } * } */ // ä¸é£ã®ã³ãã³ãã®åççæ function get_cmd_list($ptn, $bk_arr, $pre_flg = false) { $cmd_arr = array(); $diffstr = ""; if ($pre_flg){ // 32æ¥ä»¥ä¸æã®darãã¡ã¤ã«ã®åé¤ã³ãã³ãçæ $cmd = "for i in `/usr/bin/find " . bk_base . ' -name "*full*.dar" -mtime +32 ` ; do /bin/rm -f $i ; done ; ' ; $cmd_arr[] = $cmd; $cmd = "for i in `/usr/bin/find " . bk_base . ' -name "*diff*.dar" -mtime +32 ` ; do /bin/rm -f $i ; done ; ' ; $cmd_arr[] = $cmd; }else{ // darããã¯ã¢ããã®é 次å®è¡ã³ãã³ãçæ foreach($bk_arr as $k => $v){ $dname = $v["t"]; $fullpath_h = bk_base . "/" . $dname . "-full-"; $bkpath_h = bk_base . "/" . $dname . "-" . $ptn . "-"; $bkpath = $bkpath_h . date("YmdHi"); $tgt = " -R /{$dname} "; $no_tgt = ""; if ("diff" === $ptn){ $cmd = "/bin/ls -tr " . $fullpath_h . '*.dar|tail -n1 ' ; echo $cmd . "\n" ; $lsf = system($cmd); if (!$lsf){ // echo " -----basefile none_a\n" ; continue; } $lsf = preg_replace("/^(.+)\.\d+\.dar$/iu", "\\1", $lsf); $diffstr = " -A " . $lsf ; } if (isset($v["p"])){ foreach($v["p"] as $k2 => $v2){ $no_tgt .= " -P " . $v2 ; } } $tgt .= $no_tgt ; $cmd_arr[] = " nice -n 10 dar " . option_param . " -c {$bkpath} {$tgt} {$diffstr} "; } } return $cmd_arr; } exit; ?>
$option ã®ãªãã·ã§ã³ãã©ã¡ã¼ã¿ã¯http://dar.linux.free.fr/doc/man/dar.html ã man darãä»ã®æ¹ã®dar解説ãµã¤ããã確èªãã ããã
- y9ã¯å§ç¸®ã¬ãã«
- Zã§å§ç¸®ä¸è¦ãã¡ã¤ã«ãå§ç¸®å¯¾è±¡ã«ããªãã
ã¿ãããªã®ã1è¡æ¯ã«è¨è¿°ãã¾ãã
$bk_arr ã®é
åé¨åã§ããã¯ã¢ãã対象ã®/ç´ä¸ã®ãã£ã¬ã¯ããªåã¨ãããã¯ã¢ããé¤å¤å¯¾è±¡ã®ãã£ã¬ã¯ããªåãæå®ãã¾ãã
ä¾ãã°
array("t"=>"usr","p"=>array("local/delegate")),
ã®é¨åã§ã¯/usrãããã¯ã¢ãã対象ã«å«ãããã/usr/local/delegeteã¯ããã¯ã¢ãã対象ããé¤å¤ãã¦ãã¾ãã
get_cmd_list()
ã®é¨åã§ã¯darãã¡ã¤ã«ã®ä½æã³ãã³ãã¨ã32æ¥ä»¥ä¸æã®darãã¡ã¤ã«ã®åé¤ã³ãã³ããçæãã¦ãã¾ãã
- /root/bin/dar_backup.php -fã§å¼ã°ããå ´åã«ã¯ãã«ããã¯ã¢ããã
- /root/bin/dar_backup.php -dã§å¼ã°ããå ´åã«ã¯ææ°ã®ãã«ããã¯ã¢ããããã¼ã¹ã«å·®åããã¯ã¢ããã
çæããããã«ãã¦ãã¾ãã
32æ¥ä»¥ä¸æã®darãã¡ã¤ã«ãåé¤ããã¨ã6/1ã«ãã«ããã¯ã¢ãããåã£ãå¾ã® 5/28ã®å·®åããã¯ã¢ããã¨ãã¯ã¯ã£ããè¨ã£ã¦ã´ãã§ãããã®ãããã¯å¥½ãã«èª¿æ´ãã¦ãã ããã以åã¯VPSå é¨å´ä¿åæéã96æ¥ã«ãã¦ããã®ã§ãããã£ã¹ã¯å®¹éã®é¢ä¿ã§æ念ãã¾ãããï¼VPSå´å é¨ã§ã¯31æ¥ä¿æããæå ã«è»¢éããã¨ãã«å·¥å¤«ãã¦æå ã§ã¯3ã¶ææ®ãæ§æã«ããã®ãè¯ããã¨æãã¾ããï¼
ä¸ã§ã´ãã§ã´ãã§ãªããããããåãã¦ãã¾ããããã§$optionã¨$bk_arrã®ãã©ã¡ã¼ã¿ãã
nice -n 10 dar -v -D -m 256 -y9 -Z "*.gz" -Z "*.Z" -Z "*.bz2" -Z "*.tgz" -Z "*.lzh" -Z "*.zip" -Z "*.jpg" -Z "*.JPG" -Z "*.jpeg" -Z "*.JPEG" -Z "*.png" -Z "*.PNG" -Z "*.gif" -Z "*.GIF" -Z "*.mpg" -Z "*.MPG" -Z "*.mpeg" -Z "*.MPEG" -Z "*.mp3" -Z "*.rm" -Z "*.jar" -Z "*.exe" -Z "*.EXE" -Z "*.msi" -Z "*.MSI" -Z "*.divx" -Z "*.flv" -Z "*.mov" -Z "*.wma" -Z "*.iso" -Z "*.img" -Z "*.ISO" -Z "*.IMG" -Z "*.swf" -Z "*.slc" -Z "*.class" -c /backup/local/dar_file/var-diff-201206230037 -R /var -P cache -P spool/squid -P log -P named/chroot/proc -A /backup/local/dar_file/var-full-201206010340
ã®æ§ãªåªæãä½ã£ã¦ãã¾ããç§å¦ã¨ãªãã¨ãããã¨ãã§ç©èªã¯å§ã¾ãï¼ã¨ããç§å¦ã®ã¤ã³ãªãã¨ãããï¼
ä¸è¨ã®ã¹ã¯ãªãããåããã¦ã¿ã
åããã¨ãããªæãã§ããããã¨ããã¯ã¢ãããã¡ã¤ã«ãçæããã¾ããmysqlã®ããã¯ã¢ããã¯ãã£ã¹ã¯å®¹éç¯ç´ã®ããã«ææ°åã®ã¿ãä¿åããã¦ãã¾ãã
ï¼æå å´é¯ã¸ã®è»¢éæã«æ¥ä»ãã¨ãã£ã¬ã¯ããªãä½æãã¦ãã¡ã¤ã«ãä¿ç®¡ãã¦ãã¾ããï¼
ãã£ã¹ã¯å®¹é15GBã®VPSã§/backup以ä¸ã¯1.6GBä½ã§ãã
ï¼æ¥æ¬¡å·®åéã«ãã£ã¦å¤ãã£ã¦ãã¾ããããã¯æ®ã©æ´æ°ã®ç¡ããµã¼ãã¼ï¼
ç¶ãã¯ä¸ç·¨ï¼æå ï¼ãã¼ã«ã«ï¼é¯å´ç·¨ã¸ã
ï¼åã®è¯ã人ã¯ããã ãã§ãªãã¨ããªãã¨æãã¾ããå¾ç·¨ã¯å®éã«åããã¦rsyncããã話ï¼ããã¯ã¢ããããã®å¾©å ä¾ã®ã話ã§ããï¼
ã§ã¯ã§ã¯ï¼