#!/usr/bin/bash

#Tate:2022.3.24
#Author:Yingjian
#function: 定时备份root、普通用户计划任务
#必须为root用户执行 sudo用户 请在所有的命令前在sudo
#env

workdir=`cd $(dirname $0);pwd`
same_day=`date +%F`
seven_day_age=`date -d '-7 day' "+%F"`
backup_dir=/data/backup

cat > $workdir/user_list.txt << EOF
root
EOF

while read line
do
cp -ar /var/spool/cron/$line $backup_dir/$line-$same_day
done < $workdir/user_list.txt

find $backup_dir -iname "*-$seven_day_age" -exec rm -rf {} \;
