easy backup system 2

It's time for backup again 🙂 Yesterday I realized, that i forgot to do any backups and all the files are real on 2 machines. Dam still has an option to save. Since the machine is a test there is no need for who knows how many plastic recovery system so I turned to my old script in which there is some primitive functionality. In general, it is extremely ugly and lacks some functionality, for example, it is kept only 1 archive separately that the code is quite static with these iterations. So I decided to rewrite it, as this time did not scratch it for 10 minutes. In their new version they are already supported 10 old backup file. Which is a good number.


#path to tar command
TAR="$(which tar) cvzf"

function backup {

#path to beckup folder
cd $1

#remove oldest archive
rm -r *.10.tgz
sleep 3 #time for removing

#move old archives, we will save 10 old files
for i in {9..1}
let "n=$i+1"
mv "www.$i.tgz" "www.$n.tgz"
mv "mysql.$i.tgz" "mysql.$n.tgz"
mv "cron.$i.tgz" "cron.$n.tgz"

#and move the newest : )
mv www.tgz www.1.tgz
mv mysql.tgz mysql.1.tgz
mv cron.tgz cron.1.tgz

#path to first folder
$TAR www.tgz /var/www/
sleep 2
#path to second folder
$TAR mysql.tgz /var/lib/mysql/
sleep 2

#call backup function with folder path arg
backup /media/backup1
sleep 2
backup /media/backup2


In general, things are clear. I have 2 mounted partitions for backup in / media and the new archives are poured into them, before that the old ones are renamed. The structure of the names is obvious and with the ls command the landmark is intuitive.

Enhanced by Zemanta

Leave a Reply

Your email address will not be published.

Anti SPAM *