Linux自动备份服务器
定时删除任务,vim /etc/crontab
30 2 * * * find /backup/mysqlbackup -mtime +3 -exec rm -rf {} \;
40 2 * * * find /backup/opt -mtime +3 -exec rm -rf {} \;
50 2 * * * find /backup/nginx -mtime +3 -exec rm -rf {} \;
backupmysql.sh
#!/bin/sh
#filename=`date +%Y_%m_%d`
#mysqldump --all-databases -uroot -pc7La7bU6Q%k8 > /backup/mysqlbackup/mysql$file.sql
# File: /home/backupmysql.sh
# Database info
#DB_NAME1="jz_db"
#DB_NAME2="gh_jz_uc"
#DB_NAME3="gh_jz_cms"
#DB_NAME4="gh_jz_mimosa"
#DB_NAME5="gh_jz_operate"
#DB_NAME6="gh_jz_settlement"
#DB_NAME7="gh_jz_tulip"
#DB_NAME8="jz_quartz"
DB_USER="root"
DB_PASS="c7La7bU6Q%k8"
# Others vars
BIN_DIR="/usr/local/mysql/bin"
BCK_DIR="/backup/mysqlbackup"
#DATE=`date +%F`
DATE=`date +%Y_%m_%d`
# TODO
#$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS $DB_NAME1 | gzip > $BCK_DIR/db_$DATE.gz
#$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS $DB_NAME1 | gzip > $BCK_DIR/$DB_NAME1_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS jz_db | gzip > $BCK_DIR/jd_db_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS gh_jz_uc | gzip > $BCK_DIR/gh_jz_uc_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS gh_jz_cms | gzip > $BCK_DIR/gh_jz_cms_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS gh_jz_mimosa | gzip > $BCK_DIR/gh_jz_mimosa_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS gh_jz_operate | gzip > $BCK_DIR/gh_jz_operate_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS gh_jz_settlement | gzip > $BCK_DIR/gh_jz_settlement_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS gh_jz_tulip | gzip > $BCK_DIR/gh_jz_tulip_$DATE.gz
$BIN_DIR/mysqldump --opt -u$DB_USER -p$DB_PASS jz_quartz | gzip > $BCK_DIR/jz_quartz_$DATE.gz
backupopt.sh
#!/bin/sh
date=`date +%Y_%m_%d`
backup_dir="/backup/opt"
tar -zcvf $backup_dir/"opt"_$date.tar.gz /opt