variousscripts/crontabbackupdaily/backup.sh

47 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# simple backup script for everyday cron execution
# after execution `crontab -e` add new line to crontab schedule:
# @daily sh /home/user/backup.sh
# files and dirs for backup:
backups[0]=/home/user/some.file
backups[1]=/home/user/somedir
# dir for archives:
SAVEDIR=/home/user/archive/
# number of days for backup
DAYS=5
WEEKS=10
# create archive with file name 'arc.tar.gz'
tar -cvzf ${SAVEDIR}arc.tar.gz ${backups[*]}
# save last WEEKS
if [ -e ${SAVEDIR}arc-w1.tar.gz ]
then
oneweek=${SAVEDIR}arc-w1.tar.gz
oneweekripen=`find ${SAVEDIR}arc-w1.tar.gz -type f -mtime +10`
echo $oneweek
echo $oneweekripen
if [ "$oneweek" = "$oneweekripen" ]
then
for ((a=WEEKS; a >= 2 ; a--))
do
let b=a-1
mv ${SAVEDIR}arc-w${b}.tar.gz ${SAVEDIR}arc-w${a}.tar.gz
done
mv ${SAVEDIR}arc-d5.tar.gz ${SAVEDIR}arc-w1.tar.gz
fi
else
mv ${SAVEDIR}arc-d5.tar.gz ${SAVEDIR}arc-w1.tar.gz
fi
# save last DAYS
for ((a=DAYS; a >= 2 ; a--))
do
let b=a-1
mv ${SAVEDIR}arc-d${b}.tar.gz ${SAVEDIR}arc-d${a}.tar.gz
done
mv ${SAVEDIR}arc.tar.gz ${SAVEDIR}arc-d1.tar.gz
exit 0