Contents
1.Website data backup
Backup under /var/www/html
①Create backup script file
1 2 |
# cd /var/www/system # vi backup_html.sh |
Contents of html_backup.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/bash TODAY=`/bin/date +%Y%m%d` DAY_AGO=`/bin/date --date '10day ago' +%Y%m%d` HTML_DIR="/var/www/html" BACKUP_DIR="/var/www/backup/html_bak" RUN_FLAG="/var/www/backup/html_bak/html_flag" /bin/mkdir -p ${BACKUP_DIR} /bin/touch ${RUN_FLAG} /bin/tar vfcz ${BACKUP_DIR}/html_back_${TODAY}.tar.gz ${HTML_DIR} /bin/chmod 644 ${BACKUP_DIR}/html_back_${TODAY}.tar.gz if [ -f ${BACKUP_DIR}/html_back_${DAY_AGO}.tar.gz ]; then /bin/rm -f ${BACKUP_DIR}/html_back_${DAY_AGO}.tar.gz fi /bin/rm -f ${RUN_FLAG} |
➁authorization
1 |
# chmod 700 backup_html.sh |
➂Create save directory
1 2 |
# mkdir -p /var/www/backup/html_bak # chmod 777 /var/www/backup/html_bak |
④Add settings to cron for periodic backups
1 2 |
# crontab -e 0 6 * * */var/www/system/backup_html.sh > /dev/null 2>&1 ←Backup performed daily at 6:00 a.m. |
2.MySQL database backup
①Create backup script file
1 2 |
# cd /var/www/system # vi db_my_backup.sh |
Contents of db_my_backup.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#!/bin/bash MYUSER="root" MYPASS="xxxxxxxxxxx" #MySQL connection password TIME_STRING=`/bin/date '+%Y%m%d'` DAY_AGO=`/bin/date --date '10day ago' +%Y%m%d` DB_BAK_DIR="/var/www/backup/db_bak" RUN_FLAG="${DB_BAK_DIR}/db_my_flag" MYSQL_BACKUP_FILE=${DB_BAK_DIR}/mysql_backup_"${TIME_STRING}".dump /bin/mkdir -p ${DB_BAK_DIR} /bin/touch ${RUN_FLAG} mysqldump -u${MYUSER} -p${MYPASS} --all-databases > ${MYSQL_BACKUP_FILE} /bin/gzip ${MYSQL_BACKUP_FILE} if [ -f ${DB_BAK_DIR}/${MT_DB}"${DAY_AGO}".dump.gz ]; then /bin/rm -f ${DB_BAK_DIR}/${MT_DB}"${DAY_AGO}".dump.gz fi if [ -f ${DB_BAK_DIR}/${XOOPS_DB}"${DAY_AGO}".dump.gz ]; then /bin/rm -f ${DB_BAK_DIR}/${XOOPS_DB}"${DAY_AGO}".dump.gz fi if [ -f ${DB_BAK_DIR}/${GEEKLOG_DB}"${DAY_AGO}".dump.gz ]; then /bin/rm -f ${DB_BAK_DIR}/${GEEKLOG_DB}"${DAY_AGO}".dump.gz fi /bin/rm -f ${RUN_FLAG} |
➁authorization
1 |
# chmod 700 db_my_backup.sh |
➂Creation backup storage directory
1 2 |
# mkdir -p /var/www/backup/db_bak # chmod 777 /var/www/backup/db_bak |
④Add settings to cron for periodic backups
1 2 |
# crontab -e 0 7 * * * /var/www/system/db_my_backup.sh > /dev/null 2>&1 |
3.Web configuration file (under html) restored
① Copy the HTML backup file to the "/ (root)" directory of the server to be used for restoration
1 2 |
# cd /var/www/backup/html_bak # cp html_back_xxxxxxxx.tar.gz / ←Specify the backup file with the latest date |
➁Extract the file
1 2 |
# cd / # tar zxvf html_back_xxxxxxxx.tar.gz |
4.Restore MySQL data
①Save database backup file to any directory
1 2 |
# cd /var/www/backup/db_bak # gzip -d mysql_backup_xxxxxxxx.dump.gz ←Specify the backup file with the latest date |
➁Restore MySQL
1 2 |
# mysql -u root -p < mysql_backup_xxxxxxxx.dump Enter password: ←Enter root password for MySQL |