VPSã§é㶠-ãã®ï¼ï¼ ï¼darã¨mysqldumpãã¤ãã£ã¦ãµã¼ãã¼ã®æ次ãã«ããã¯ã¢ããã¨æ¥æ¬¡å·®åããã¯ã¢ãããåãï¼ä¸ç·¨ï¼ãã¼ã«ã«é¯å´ã¸ã®è»¢éã¹ã¯ãªããã®å·»ï¼
ã¿ãªããããã«ã¡ã¯ãæ¬æ¥ã¯ä¸ç·¨ï¼ãã¼ã«ã«é¯å´ã¸ã®è»¢éã¹ã¯ãªããã®å·»ã§ãã(åç·¨ï¼VPSé¯å´ã¯ãã¡ã)
転ã°ã¬å
ã®æã転ãã å ´åã¯æ¬¡ãã転ã°ãªãããã«ããã«å¯¾çãã¾ãããï¼ä½ãåä½å®é¨ã¯ä¸å¯§ã«ãï¼
ãã¼ã«ã«é¯ï¼æå å´ï¼ã¹ã¯ãªãã
ãã¼ã«ã«ï¼æå ï¼å´ã®ããã¯ã¢ããã¹ã¯ãªããã¯ãããªæããã¹ã¯ãªãã5:rootã¦ã¼ã¶ã¼ã®crontab -e
45 06 * * * /root/bin/backup_sasv01.sh >/backup/remote/sasv01.log 2>&1 #55 06 * * * /root/bin/backup_sasv02.sh >/backup/remote/sasv02.log 2>&1
å®éã¯ãã®ãã¼ã«ã«(æå å´ï¼ã®èªé¯èªä½ã®ããã¯ã¢ããã¹ã¯ãªããããååã¨ã³ããªã¼ã®ã¹ã¯ãªãã1ã®æ§ã«èµ°ããã¦ãã¾ãã説æã§ã¯çç¥ãã¾ãã
VPSé¯ã®æ次ï¼æ¥æ¬¡ã®ããã¯ã¢ãããã¡ã¤ã«éã3æ-4æå°ã«ä½æå®äºããæå ã®èªé¯èªä½ã®ããã¯ã¢ãããå®äºããå¾ã®é åããè¦è¨ãã£ãæ©æ6æå°é ã«
/root/bin/backup_sasv01.sh /root/bin/backup_sasv02.sh
â¦ã¨ãã£ã/root/bin/backup_VPSå´ãµã¼ãã¼å.shãé 次起åãã¦ãã¾ãã
VPSé¯ãå¢ãããã¯ã¢ãã対象ãå¢ããååã ãã
- mkdir -p /backup/remote/sasv01/dailybk;
- mkdir -p /backup/remote/sasv01/dar_file;
- chmod -R 600 /backup/remote/sasv01
ã®æ§ã«ããã¯ã¢ãããã¡ã¤ã«è¨ç½®ç¨ãã£ã¬ã¯ããªãæåã§ä½æãã¦ãã¾ãã
ã¾ãã/backup/ã®ãã¼ããã·ã§ã³çãæ°ãã¤ãã¦ãã ãããï¼å¥é¯ã®æ å ±ãè©°ã¾ã£ãéè¦ãã¡ã¤ã«ãªã®ã§chmod 600 /backupã§root以å¤ä¸ç¨æã«è¦ããªãããã«ãã¦ããï¼
ãã£ã¬ã¯ããªæ§æã®å³
/backup/local/以ä¸ãæå
ã®èªé¯ã®ããã¯ã¢ããä¿åé å
/backup/remote/VPSå´ãµã¼ãå1/,/backup/remote/VPSå´ãµã¼ãå2/ 以ä¸ãVPSé¯å´ã®ä¿åé å
ã¹ã¯ãªãã6:/root/bin/backup_VPSå´ãµã¼ãã¼å1.sh
å¤ããã¡ã¤ã«ãåé¤ãã¦rsyncã§è»¢éãã¦ãã ãã§ããï¼èªè¨¼éµã®ã¿ã§ã®sshæ¥ç¶çã¯æ¢ã«åºæ¥ãæ§ã«ãªã£ã¦ããåæã§ããï¼
å¤ããã¡ã¤ã«ãåé¤ããããããã¨ãåé¤ããªãããä¿åæ¥æ°ãä½æ¥ã«ãããçã¯ç°å¢ã«ãã£ã¦å¤ãã£ã¦ããã¨æãã¾ãã
ç§ã®å ´åããããæ´ã«é常ã¯ç¹ãã§ããªãå¤ä»ãHDDã«æ¯æ1度æ¥ç¶ãã¦rsync(deleteç¡ãï¼ããã¦åãå¤ããå¥ã®å ´æã«ä¿ç®¡ãã¦ãã¾ãã
ï¼ï¼æéè¦ãã¡ã¤ã«ã¯ç©ççã«é¢ããå¥ã®å ´æã«ã転éï¼å¥é¯ã«ãæå·åãã¦ä¿ç®¡ãã¦ãã¾ãã
å°éé·ç«äºæ°´å®³çªçã§ã®ç ´æç´å¤±ãèãéè¦åº¦ã«ãããã¾ããæé«5éä½ã®ä¿®å¾©ã«ã¼ãã«ãã¦ãã¾ããï¼
#!/bin/sh NOW=`date +%Y%m%d` BASE_DIR="/backup/remote/sasv01/dailybk" #VPSå´ãµã¼ãåã®ãã£ã¬ã¯ããªã«å¿ ãæ¸ãæãã LOCALDAR_DIR="/backup/remote/sasv01/dar_file" #VPSå´ãµã¼ãåã®ãã£ã¬ã¯ããªã«å¿ ãæ¸ãæãã PORT="10222" #VPSãµã¼ãã¼å´ãã¼ãçªå·ãå¿ ãæ¸ãæããã(æ¨æº22) SVUSR="[email protected]" #VPSã«sshæ¥ç¶ããã¦ã¼ã¶ã¼å@æ¥ç¶å (sshã¦ã¼ã¶ã¼å@IPã¢ãã¬ã¹)å ¬ééµèªè¨¼ã§ãã¼ãã¹ã¯ã¼ãæ¥ç¶å¯è½ãªããã¯ã¢ãããã¡ã¤ã«è»¢éå°ç¨ã¦ã¼ã¶ã¼ãä½æãã¦ããããã®ã¦ã¼ã¶ã¼ã®æä½åºæ¥ãç¯å²ãéå®ãããå ´åã¯opensshå´è¨å®ã§è¦èª¿æ´ï¼è§£èª¬çç¥ï¼ LOCAL_DIR="$BASE_DIR/$NOW" #ãã¼ã«ã«ï¼æå ï¼å´ã®æ¥ä»æ¯ãã£ã¬ã¯ã㪠#VPSãµã¼ãã¼å´ã®ããã¯ã¢ããä¿åç¨ãã£ã¬ã¯ããªãåå¨ããªãå ´åã¯ãããã¦èªåã§ä½ããªãã§å¦ççµäº if [ ! -e "$BASE_DIR" ]; then echo "$BASE_DIR not exists ,exit" exit 1 fi if [ ! -e "$LOCALDAR_DIR" ]; then echo "$LOCALDAR_DIR not exists ,exit" exit 1 fi #æ¬æ¥ã®æ¥ä»yyyymmddã®ãã£ã¬ã¯ããªãåå¨ããªãå ´åã¯çæãåå¨ããå ´åã¯ãããå¦ççµäº if [ ! -e "$LOCAL_DIR" ]; then mkdir $LOCAL_DIR else echo 'dir exists' exit 1 fi cd $BASE_DIR #96æ¥ä»¥ä¸æã«touchãããdailybké ä¸ã®20*ã§å§ã¾ããã£ã¬ã¯ããªã¯èªååé¤ #ï¼VPSå´ã§ã¯31æ¥ä¿ç®¡ãæå å´ã§ã¯95æ¥ä¿ç®¡ï¼ #æå å´ãã£ã¹ã¯å®¹éãèãæä½32æ¥ä»¥ä¸ã§åèªè¦èª¿æ´ find $BASE_DIR -mtime +96 -type d -name "20*"|xargs rm -rf #96æ¥ä»¥ä¸æã«touchããã*.darãã¡ã¤ã«ã¯èªååé¤ find $LOCALDAR_DIR -mtime +96 -type f -name "*.dar"|xargs rm -f #ãªã¢ã¼ãï¼VPSãµã¼ãã¼å´ï¼ããrsyncã§mysqlã®ãã³ããã¡ã¤ã«ã¨darã®ã¢ã¼ã«ã¤ããã¡ã¤ã«ãåä¿¡ nice -n 19 rsync -auvz -e "ssh -p $PORT" $SVUSR:/backup/local/dailybk/ $LOCAL_DIR nice -n 19 rsync -auvz -e "ssh -p $PORT" $SVUSR:/backup/local/dar_file/ $LOCALDAR_DIR
- æå ã«ãã96æ¥ä»¥ä¸æã«touchããããã¡ã¤ã«ã¯åé¤ããrsync(deleteãªãã·ã§ã³ç¡ãï¼ã§VPSãµã¼ãå´ã®ã¿ã«ãããã¡ã¤ã«ã転éãã¦ãã¾ãã
- mysqlã®ãã³ããã¡ã¤ã«ã¯VPSå´ã«ã¯ææ°1æ¥åããããã¯ã¢ãããåãã¦ããªãã§ããããã¼ã«ã«å´ã§ã¯96æ¥ä¿ç®¡ã¨ãã¦ãã¾ããï¼96=3ã¶æã¨ã¡ãã£ã¨ï¼æ°æ¥åã¯ãã¼ã¸ã³ï¼
- å³å¯ã«ã¯å®å ¨ã®ããã«ååã®ã¹ã¯ãªãã3ãæ¹é ãVPSå´ã«7æ¥åãæå å´ã«96æ¥åä¿ç®¡ã®æ§ã«ããã»ãããæå å´é¯è½ã¡ã«ãããã¡ã¤ã«è»¢éæ¼ãã§ã®mysqldumpããã¯ã¢ããæ¯æããé²æ¢ã§ããã®ã§è¯ããã¨æãã¾ãã
- ç§ã®å ´åVPSã®ãã£ã¹ã¯å®¹éãå°ãªãï¼ãã©ã³ã¶ã¯ã·ã§ã³ç¡ãã®éçã«è¿ãCMSã³ã³ãã³ããããªãï¼ä½ãé¯ã«ãã£ã¦ã¯DBã®æ°ã¯å¤ãã®ã§å®¹éã¯é£ãï¼ï¼ææªã§ãæ次+æ¥æ¬¡å·®ådarã®ä¸ã«å«ã¾ãã¦ãã/var/lib/mysql/DBå/* ãããã¼ã¿ãæ»ããããmysqldumpã«ã¤ãã¦ã¯ãã®ããã«ãªã£ã¦ãã¾ãã
- åæ¥ã¨ã³ããªã¼ã®ã¹ã¯ãªãã3ã®ã³ã¡ã³ãã«å¾ãVPSå´ã«ã3æ¥åmysqlã®ãã³ããä¿åããããã«ããå ´åã«ã¯ãæ¯æ¥çæããã /backup/remote/VPSé¯å/dailybk/yymmdd/ 以ä¸ã«3æ¥åã®mysql_dailybk_mysqldump_yyyymmdd.tar.gzããä¿åãããããã«ãªãã¾ããVPSå´ã»ãã¼ã«ã«å´ã®ç©ºã容éãååã«ããå ´åã«ã¯ãã³ãã¼ã®å¤ããã¡ãã®ã»ããããå®å ¨ã§ãã
å¾ç·¨(ããã¯ã¢ããï¼è»¢éåä½ç¢ºèªï¼ããã¯ã¢ããããã®å¾©å 確èªç·¨ï¼ã«ç¶ãã
ä»æ¥ã¯å¿ããã®ã§ããã¾ã§ã