首页 > 代码库 > 备份数据删除和腾讯云数据库下载
备份数据删除和腾讯云数据库下载
#!/bin/bash base_dir=/data/Mysql-BackCenter delete_day=30 delete_log_dir=/data/log/delete download_dir=$base_dir/ZZB-7 vardate=$(date +%Y%m%d) datebefore=$(date -d "1 days ago" +%Y%m%d) cdmdump=$base_dir/cdb_dump_tool [[ -d $delete_log_dir ]] || mkdir -p $delete_log_dir print_to_log(){ echo "[ $(date "+%Y-%m-%d %H:%M:%S") ] $1" >> $delete_log_dir/delete.log } print_log(){ echo "[ $(date "+%Y-%m-%d %H:%M:%S") ] $1" >> $delete_log_dir/download.log } function delete_file(){ delete_total_num=$(find $base_dir -type f -mtime +$delete_day |grep "tar.gz$"|wc -l) print_to_log "开始删除$delete_day天前的数据压缩包..." print_to_log "删除数量:$delete_total_num" if [[ $delete_total_num -ne 0 ]];then for i in $(find $base_dir -type f -mtime +$delete_day |grep "tar.gz$") do print_to_log "开始删除: $i" rm -f $i if [[ $? -eq 0 ]];then print_to_log "删除$i,成功!" else print_to_log "删除$i,失败...!" fi done else print_to_log "$delete_day天前的历史压缩数据不存在..." fi print_to_log "删除结束." } function download_sql(){ cd $base_dir [[ -d $download_dir/$vardate ]] || mkdir -p $download_dir/$vardate $cdmdump APPID 实例名称 $datebefore $download_dir/$vardate if [[ $? -eq 0 ]];then print_log "Download 实例名称 $datebefore 成功!" download_file_size=$(du -sh $download_dir/$vardate |awk ‘{print $1}‘) print_log "$download_dir/$vardate 源目录大小: $download_file_size" cd $base_dir/$download_dir tar -zcf $vardate.tar.gz $vardate rm -fr $download_dir/$vardate else print_log "Download 实例名称 $datebefore 失败!" fi } delete_file download_sql
备份数据删除和腾讯云数据库下载
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。