add db backup to crontabbackupdaily
This commit is contained in:
parent
e33d458a8a
commit
1bb31b9a85
|
@ -1,6 +1,5 @@
|
||||||
### crontab backup daily
|
### crontab backup daily
|
||||||
Simple backup script for everyday cron execution.
|
Simple backup script for everyday cron execution. Make the file executable and after execution `crontab -e` add new line to crontab schedule:
|
||||||
After execution `crontab -e` add new line to crontab schedule:
|
|
||||||
```
|
```
|
||||||
@daily sh /home/user/backup.sh
|
@daily /home/user/backup.sh
|
||||||
```
|
```
|
|
@ -3,18 +3,32 @@
|
||||||
# after execution `crontab -e` add new line to crontab schedule:
|
# after execution `crontab -e` add new line to crontab schedule:
|
||||||
# @daily sh /home/user/backup.sh
|
# @daily sh /home/user/backup.sh
|
||||||
|
|
||||||
|
# dir for archives:
|
||||||
|
SAVEDIR=/home/user/archive/
|
||||||
|
|
||||||
# files and dirs for backup:
|
# files and dirs for backup:
|
||||||
backups[0]=/home/user/some.file
|
backups[0]=/home/user/some.file
|
||||||
backups[1]=/home/user/somedir
|
backups[1]=/home/user/somedir
|
||||||
# dir for archives:
|
# mysql databases for backup:
|
||||||
SAVEDIR=/home/user/archive/
|
db[0]=databasename1
|
||||||
|
db[1]=databasename2
|
||||||
# number of days for backup
|
# number of days for backup
|
||||||
DAYS=5
|
DAYS=5
|
||||||
WEEKS=10
|
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'
|
# create archive with file name 'arc.tar.gz'
|
||||||
tar -cvzf ${SAVEDIR}arc.tar.gz ${backups[*]}
|
tar -cvzf ${SAVEDIR}arc.tar.gz ${backups[*]}
|
||||||
|
|
||||||
|
# remove db backups
|
||||||
|
rm ${dbbackups[*]}
|
||||||
|
|
||||||
# save last WEEKS
|
# save last WEEKS
|
||||||
if [ -e ${SAVEDIR}arc-w1.tar.gz ]
|
if [ -e ${SAVEDIR}arc-w1.tar.gz ]
|
||||||
then
|
then
|
||||||
|
|
Loading…
Reference in New Issue