I have a server(centOS) with plesk installed and I need to planning some backups for each day.
Plesk allows only one planned backup, so I created this solution:
- Create every night a backup inside a folder
- Launch a script that will read the day from the title of a txt file inside the folder (launched every night via cronTAB)
- Move the backup file inside the correct directoy (based on the name of the day)
- Change the name of the day in the title of the txt
This is my script (not tested right now):
BACKUPNAME="backupname"
cd /backup/daily
find . -type f | while IFS= read filename; do
case "${filename,,*}" in
mon.txt) mv $BACKUPNAME ../mon
mv mon.txt tue.txt;;
tue.txt) mv $BACKUPNAME ../tue
mv tue.txt wed.txt;;
wed.txt) mv $BACKUPNAME ../wed
mv wed.txt thu.txt;;
thu.txt) mv $BACKUPNAME ../thu
mv thu.txt fri.txt;;
fri.txt) mv $BACKUPNAME ../fri
mv fri.txt sat.txt;;
sat.txt) mv $BACKUPNAME ../sat
mv sat.txt sun.txt;;
sun.txt) mv $BACKUPNAME ../sun
mv sun.txt mon.txt;;
* : ;; #nothing
esac
done
Do you think is it a good/stable solution?
Thanks!
2
Answers
I don’t know what you mean with “only one planned backup”, could you explain this?
On the other hand, why not doing an rsync and deleting the oldest ones if needed… This is how I do this:
This script is called every day via cron, and it makes a full backup of “/” excluding everything listed in $HOME/.rsync/exclude.
The backups are stored in /COREBACKUP/Backups/back-$date, the latest backup is stored in /COREBACKUP/CurrentBackup.
It works fine, although it could’ve been written more user friendly 😉
Rotating the backup destination depending on day is reasonable, but the name-generation method shown in the question depends on the system running once daily. If the system were shut down for a day, or if the script ran twice in a day, your
mon.txt
,tue.txt
, … sequence would go out of sync. Instead of using a filename and a clunky case statement to get the name of the destination directory, use code like the following:If the backup file belongs to a different day than current, use a
date
form like one of the following, which respectively setday
to the name of yesterday, or to the name of the day when the file was last modified.