scripts/backup.sh
sayan df2d6caf12 Finalement, on ignore les erreurs inintressantes
--
Sayan

darcs-hash:20031224100130-d1356-5593ed8813eb120f65c8ac2fcbb6cdfa194d11b5.gz
2003-12-24 11:01:30 +01:00

59 lines
2 KiB
Bash
Executable file

#!/bin/sh
## Sauvegarde des fichiers de conf et du site web CRANS sur Tanek
## Sayan 02/10/2003
## Ajout de la synchro du site web : Sayan 04/10/2003
## Ajout de la synchro des mails : Sayan 19/10/2003
## Ajout de la synchro des news et des homes : Sayan 15/11/2003
## Nom de fichiers et chemins
temp_dir=$(mktemp -d)
nom_archive=$temp_dir"/backup_"$(hostname)"_"$(date --iso-8601)".tar.bz2"
nom_selections=$temp_dir"/selections"
## Que sauvegarder ?
# via tar bzip2
confs="etc usr/cvs-rep CRANS usr/scripts boot/config*"
# via rsync
site_web="/home/httpd/CVS-Repository"
mails="/var/spool/mail"
news="/var/spool/news"
homes="/home"
cd /
# tgz le contenu des répertoires
# ajoute dpkg --get-selections
# echo Preparing to backup configs...
dpkg --get-selections > $nom_selections || exit 1
tar -cjf $nom_archive $confs .$nom_selections || exit 2
# echo Sending configs to tanek...
scp $nom_archive backupcrans@tanek: || exit 3
# rsync over ssh pour le site web, les homes, les mails et les news
# archive, compress, sparse, hard links, CVS exclude, remote shell
# archive is rlptgoD : recursive, symlinks, perms, times, group, owner, Devices
# suppr les fichiers non existant sur zamok
# synchro journalière, switch par semaine
week=$(date +%W) # numéro de la semaine
week_mod2=$(( $week % 2 ))
rsync -azSHe ssh --delete $site_web backupcrans@tanek:~/httpd-$week_mod2 || exit 4
rsync -azSHe ssh --delete $mails backupcrans@tanek:/mnt/backup$week_mod2/var/spool || exit 5
rsync -azSHe ssh --delete $news backupcrans@tanek:/mnt/backup$week_mod2/var/spool || exit 6
# Les homes sont donnés à backupcrans.backup
# "Permission denied" errors occur because backupcrans is not root on tanek. Ignoring
temp=$(mktemp)
temp_mail=$(mktemp)
rsync -azSHe ssh --delete $homes backupcrans@tanek:/mnt/backup$week_mod2 &>$temp
grep -vie "permission denied" $temp | grep -vie "skipping non-regular file" | grep -vie "partial transfer" > $temp_mail
if [ -s temp_mail ]
then
mail roots -s "rsync error" < $temp_mail || exit 7
fi
# clean
rm -rf $temp_dir
rm $temp
rm $temp_mail