Shell Script: backup of the subversion repositories
Translation of the original in Catalan. Read it in: CatalàCastellano
Last week I made a small shell script to back up the software repositories of my server. Basically what it does is look in /var/svn/repos to see which directories are there. Then it launches an svnadmin dump and at the same time compresses the output with bzip2 into a file; afterwards this file is stored in /home/backup/subversion, which is a network drive mounted to make backups on the server. The last detail I need to mention is that, after making the copy of the file, it leaves 3 files of each repository in the backup directory and deletes the rest. In this way I have 3 copies of each of the repositories, one from yesterday, the other from the day before yesterday and finally one from 3 days ago. So if any inconsistency disaster or something similar happens I have more room to recover the repository.
You will see that the code is very simple and if anyone wants to adapt it I don't think it will be hard for them, everything is programmed with typical commands, no weird commands or anything. Finally the only thing I had to do is put it in the cron at some time in the early morning.
#!/bin/sh
BASE="/var/svn/repos"
DATA=`date "+%Y%m%d"`
cd $BASE
REPOSS=`find . -maxdepth 1 -mindepth 1 -type d | cut -f 2 -d "/"`
BACKUPDIR="/home/backup/subversion"
for REPOS in $REPOSS
do
BACKUPFITXER=backup-repos-$REPOS
FITXER=$BACKUPFITXER-$DATA.dump.bz2
echo -n "Starting $REPOS backup..."
svnadmin dump -q $BASE/$REPOS | bzip2 > $FITXER 2>/dev/null
mv $FITXER $BACKUPDIR
cd $BACKUPDIR
rm -f `ls -t $BACKUPFITXER* | sed -e 1,3d` 2> /dev/null
echo "OK"
cd $BASE
done2 comments
Comments from the old blog, as they were written. Comments are closed.
sabueso
Has probado alguna vez Bacula ? El dia que lo tengas rulando fliparas de como te olvidas de los backups , se encarga de todo , los cataloga y la restauracion es muy simple.
Yo desde siempre he sido partidario de montar scripts para las copias , pero desde que uso Bacula he dejado de programarlos.
—
[1]
Doncs si que el coneixo si, però jo necessitava una solució ràpida i que fes el que volia. De fet, no sé si bacula em faria just el que demano, o sigui, un dump. Que no és el mateix que copiar els fitxers.