|
发表于 2023-3-12 04:19:41
|
显示全部楼层
顺带分享我的自动备份脚本,该脚本设定每天凌晨3点运行,将MariaDB目录打包后以日期命名保存在一个文件夹,文件目录是备份了,但是将来怎么恢复我却不太清楚
脚本如下,仅供参考。
#! /bin/bash
## author: Momo Wen
## date: Feb.18 2022
## Periodically move RCU Log logs to date folder
##cd /volume1/TFTP/
##源文件夹
##source_path='/volume1/TFTP/'
source_path='/volume1/@appstore/MariaDB10/'
##目标文件夹
##target_path='/volume1/TFTP/'
target_path='/volume1/MyNas/MySQL_AUTO_BACKUP/'
##获取当前时间
RUN_TIME=`date +%H%M%S`
##压缩文件夹
##tarFolder='/volume1/TFTP/tar/'
tarFolder='/volume1/MyNas/MySQL_AUTO_BACKUP/tar/'
##取当前日期前一天
get_ydate()
{
##设置当前年月日
TODAY=`date +%Y%m%d`
month=`date +%m`
day=`date +%d`
year=`date +%Y`
##字符转换称数字
month=`expr $month + 0`
##取前一天
day=`expr $day - 1`
##如果前一天为0,进行如下处理
if [ $day -eq 0 ]; then
##取前一月月份.
month=`expr $month - 1`
##如果前一月为0,则取前一年,月份取第12月
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
##如果前一月份不为零,则根据月份来判断该天是该月的第几天
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
elif [ `expr $year % 100` -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
##按照YYYYMMDD格式打印年日期
acct_date=`printf "%04d-%02d-%02d" "$year" "$month" "$day"`
echo $RUN_TIME
echo $acct_date
mkdir $acct_date
mkdir $tarFolder
target_path=$target_path$acct_date
tarFileName="${tarFolder}${acct_date}.tar"
}
get_ydate
echo "--------------------------------------"
echo "target_path=${target_path}"
echo "source_path=${source_path}"
echo "acct_date=${acct_date}"
echo "tarFolder=${tarFolder}"
echo "tarFile=${tarFileName}"
cd $source_path
pwd
echo "--- CMD: ls -----------------"
ls
echo "--- CMD: cp -----------------"
cp -r $source_path $target_path
##echo "--- find files below -----------------"
## find $source_path -type f -maxdepth 1 -ctime -1 -name "*.dat" -print -exec mv {} $target_path \;
echo "--- CMD: tar ----------------------------"
tar -zcvf $tarFileName $target_path && rm -rf $target_path
echo "-finshied-----------------------------"
|
|