centos定时全量备份mysql
#!/bin/bash db_user="root" db_passwd="123456" db_name="fzfw" backup_dir="/home/mysqlbak" mv_backup_dir="/home/mysqloldbak" #进入备份目录将之前的移动到old目录 cd $backup_dir echo "You are in mysqlbak folder now." mv $backup_dir/* $mv_backup_dir echo "Old sqlfile are moved to mysqloldbak folder." #备份目录 #时间格式 time=$(date +"%Y-%m-%d") #mysql 备份的命令,注意有空格和没有空格 mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"-"$time.sql" echo "your database backup successfully completed:"$db_name"-"$time".sql" #这里将7天之前的备份文件删掉 SevenDays=$(date -d -7day +"%Y-%m-%d") if [ -f $mv_backup_dir/$db_name"-"$SevenDays.sql ] then rm -rf $mv_backup_dir/$db_name"-"$SevenDays.sql echo "you have delete 30days ago bak sql file :"$db_name"-"$SevenDays.sql else echo "30days ago bak sql file not exist " echo "bash complete" fi
相关推荐
changecan 2020-11-19
ECSHOP专属建设 2020-11-13
88427810 2020-11-02
步知道 2020-10-27
Junzizhiai 2020-10-10
jackalwb 2020-10-05
小网管 2020-09-03
shiwenqiang 2020-09-14
85251846 2020-09-14
summerinsist 2020-08-21
87901735 2020-08-19
PinkBean 2020-08-11
85407718 2020-08-09
MichelinMessi 2020-07-30
suosuo 2020-07-28
CARBON 2020-07-28
lizhengfa 2020-07-27
88427810 2020-07-26