一周备份一次,定时任务 1

#/bin/bash
#set -x 
#整体打包wordpress
cd /root/backup/
old_back=date -d "-7 day" +%Y%m%d
new_back=date +%Y%m%d
date=date "+%Y-%m-%d %H:%M:%S"
#删除
function del(){
    if [ -f  wordpress-v${old_back}.tar.gz ];then
        rm -f wordpress-v${old_back}.tar.gz
        echo "删除旧备份文件: wordpress-v${old_back}.tar.gz" >> /root/backup/backup.log
    fi
    if [ -f  wordpress-${old_back}.sql ];then
        rm -f wordpress-${old_back}.sql
        echo "删除旧备份sql: wordpress-${old_back}.sql ">> /root/backup/backup.log
    fi
}
#备份
function back(){

    echo "开始时间:" $date >> /root/backup/backup.log
    echo $date">>备份wordpress" >> /root/backup/backup.log
#wordpress 备份
    tar -zcvf wordpress-v${new_back}.tar.gz  /var/www/wordpress

#mysql 数据库备份
    echo $date">>备份wordpress数据库"  >> /root/backup/backup.log
    mysqldump   --defaults-extra-file=/etc/my.cnf  wordpress > ./wordpress-${new_back}.sql 
}
back
if [ $? -eq 0 ];then
    echo "备份成功!" >> /root/backup/backup.log
    del
else
    echo "备份失败!" $date >> /root/backup/backup.log
fi
    echo "结束时间:" $date >> /root/backup/backup.log
    echo -e "\n" >> /root/backup/backup.log

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

open