add db backup to crontabbackupdaily

This commit is contained in:
ivan 2022-11-26 22:13:24 +03:00
parent e33d458a8a
commit 1bb31b9a85
2 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,5 @@
### crontab backup daily
Simple backup script for everyday cron execution.
After execution `crontab -e` add new line to crontab schedule:
Simple backup script for everyday cron execution. Make the file executable and after execution `crontab -e` add new line to crontab schedule:
```
@daily sh /home/user/backup.sh
@daily /home/user/backup.sh
```

View File

@ -3,18 +3,32 @@
# after execution `crontab -e` add new line to crontab schedule:
# @daily sh /home/user/backup.sh
# dir for archives:
SAVEDIR=/home/user/archive/
# files and dirs for backup:
backups[0]=/home/user/some.file
backups[1]=/home/user/somedir
# dir for archives:
SAVEDIR=/home/user/archive/
# mysql databases for backup:
db[0]=databasename1
db[1]=databasename2
# number of days for backup
DAYS=5
WEEKS=10
# create db backups
for n in ${!db[@]}; do
dbbackups[n]=${SAVEDIR}${db[n]}.gz
mysqldump ${db[n]} > ${dbbackups[n]::-3}
gzip ${dbbackups[n]::-3}
done
# create archive with file name 'arc.tar.gz'
tar -cvzf ${SAVEDIR}arc.tar.gz ${backups[*]}
# remove db backups
rm ${dbbackups[*]}
# save last WEEKS
if [ -e ${SAVEDIR}arc-w1.tar.gz ]
then