备份数据删除和腾讯云数据库下载脚本 发表于 2014-10-14 | 分类于 Shell相关 | | 阅读次数 | 字数统计 228 | 阅读时长 1 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667#!/bin/bashbase_dir=/data/Mysql-BackCenterdelete_day=30delete_log_dir=/data/log/deletedownload_dir=$base_dir/ZZB-7vardate=$(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_dirprint_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$")doprint_to_log "开始删除: $i"rm -f $iif [[ $? -eq 0 ]];thenprint_to_log "删除$i,成功!"else print_to_log "删除$i,失败...!"fidoneelse 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 ]];thenprint_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_dirtar -zcf $vardate.tar.gz $vardate rm -fr $download_dir/$vardate else print_log "Download 实例名称 $datebefore 失败!"fi }delete_filedownload_sql 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏