定时备份代码和数据库脚本
// linux版本
# backup mysql
backupdir=/opt/backup
time=` date +%Y_%m_%d_%H_%M_%S `
db_host=192.168.1.2
db_user=root
db_pass=root
mysqldump --all-databases -h $db_host -u $db_user -p$db_pass | gzip > $backupdir/$time.sql.gz
# backup code
backupdircode=/opt/backup
time=` date +%Y_%m_%d_%H_%M_%S `
tar czvf $backupdircode/$time.code.gz /var/web/www/html
// windows版本
rem ******MySQL backup start******
@echo off
set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,1%%time:~1,1%%time:~3,2%%time:~6,2%"
E:\wamp\bin\mysql\mysql5.6.17\bin\mysqldump --opt --single-transaction=TRUE --user=root --password=root--host=127.0.0.1 --protocol=tcp --port=3306 --default-character-set=utf8 --single-transaction=TRUE --routines --events "test" > E:\www\web\bak\db\%Ymd%.sql
@echo on
rem ******MySQL backup end******
// 2024更新,linux备份和删除脚本
# backup sql
backupdir=/opt/web/backup/sql
time=` date +%Y_%m_%d_%H_%M_%S `
db_host=127.0.0.1
db_user=root
db_pass=rootpasswd
mysqldump --all-databases -h $db_host -u $db_user -p$db_pass | gzip > $backupdir/$time.sql.gz
# 超过30天的备份,删除
find $backupdir -mtime +30 -print | xargs rm
# backup code
#backupdircode=/opt/web/backup/code
#time=` date +%Y_%m_%d_%H_%M_%S `
#tar czvf $backupdircode/$time.code.gz /opt/web/www