easy backup system 2

The time has come for bek″pinga again 🙂 Yesterday I realized, that I forgot to do any backups and all the files are real 2 machines. Give another option for keeping. Because the machine is a test doesn't need much plastic recovery system so I turned to my old script in which there is some primitive functionality. Generally is extremely ugly and lupsvat known functionality to say take care only 1 Archive separately that the code is fairly static with these repetitions. Затова реших да го пренапиша, като този път не го надрасквма за 10 minutes. В новата си версия вече се подържат 10 стари backup файла. Което си една добра цифра.


#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


В общи линии нещата са ясни. I have a 2 монтирани дяла за бекъп в /media и в тях се наливат новите архиви като преди това се преименуват старите. Структурата на имената е очевидна и при ls команда ориентира е интуитивен.

Enhanced by Zemanta

leave a reply

Your email address will not be published. Required fields are marked *

anti SPAM *