Backup di una macchina Linux con rsyncd
Jump to navigation
Jump to search
La macchina client si collega via rsync ad un server che esegue rsyncd, e viene backuppata usando degli hard link per risparmiare spazio. Vengono conservati gli ultimi 7 backup
Server
- Configurare rsyncd:
sudoedit /etc/rsyncd.conf
# cat /ffp/etc/rsyncd.conf
log file = /mnt/HD_b2/backup/rsyncd.log
# percorso assoluto
use chroot = true
# per sicurezza
[sda1]
# Modulo per il primo disco
uid = 0
gid = 0
# i files vengono trasferiti usando le credenziali di root
path = /mnt/HD_b2/backup/sda1
comment = Backup Juno sda1
read only = false
numeric ids = yes
# usa gli id numerici per le permission, per evitare problemi di restore
#fake super = yes
# serve solo se rsyncd non è usato come root
pre-xfer exec = /mnt/HD_b2/backup/pretransfer > /mnt/HD_b2/backup/pretransfer.log
# script da eseguire prima dell'inizio del trasferimento
post-xfer exec = /mnt/HD_b2/backup/posttransfer > /mnt/HD_b2/backup/posttransfer.log
# script da eseguire dopo la fine del trasferimento
[sda4]
uid = 0
gid = 0
path = /mnt/HD_b2/backup/sda4
comment = Backup Juno sda4
read only = false
numeric ids = yes
#fake super = yes
pre-xfer exec = /mnt/HD_b2/backup/pretransfer > /mnt/HD_b2/backup/pretransfer.log
post-xfer exec = /mnt/HD_b2/backup/posttransfer > /mnt/HD_b2/backup/posttransfer.log
Questi sono gli script pre e post:
sudoedit /mnt/HD_b2/backup/pretransfer
#nulla
sudoedit /mnt/HD_b2/backup/posttransfer
# cat /mnt/HD_b2/backup/posttransfer
#!/bin/bash
# SHOWS all RSYNC variables
set | grep RSYNC_
#RSYNC_EXIT_STATUS=12
#RSYNC_HOST_ADDR=192.168.250.88
#RSYNC_HOST_NAME=juno.diesis.priv
#RSYNC_MODULE_NAME=sda1
#RSYNC_MODULE_PATH=/mnt/HD_b2/backup/sda1
#RSYNC_PID=7924
#RSYNC_RAW_STATUS=3072
#RSYNC_USER_NAME=
dstpath=$RSYNC_MODULE_PATH
if [ "RSYNC_EXIT_STATUS" = "0" ]
then
echo Linking $dstpath ...
LAST_LINE=$(/bin/ls $dstpath -1 | grep '2[0-9][0-9][0-9][0-1][0-9][0-3][0-9]*' | sort | tail -n1)
echo LAST_LINE=$LAST_LINE
echo cd $dstpath
echo rm -f current
echo ln -s $LAST_LINE current
echo Cleaning $dstpath ...
TOTAL_LINES=$(/bin/ls $dstpath -1 | grep '2[0-9][0-9][0-9][0-1][0-9][0-3][0-9]*' | sort | wc -l)
LINES_2DELETE=$(($TOTAL_LINES-7))
DELETE=$(/bin/ls $dstpath -1 | grep '2[0-9][0-9][0-9][0-1][0-9][0-3][0-9]*' | sort | head -n $LINES_2DELETE)
echo TOTAL_LINES=$TOTAL_LINES
echo LINES_2DELETE=$LINES_2DELETE
echo DELETE=$DELETE
if [ -z "$DELETE" ]
then
for DIR in $DELETE
do
echo Deleting $dstpath/$DIR ...
echo rm -rf $dstpath/$DIR
done
else
echo Nothing to clean.
fi
else
echo Last sync was unsuccesfull: not linking and not deleting.
fi
Client
Creare lo script:
sudoedit /home/diesis/local/bin/timemachine-sda1
#!bin/bash if [ $(id -u) != "0" ] then echo You must run echo sudo $(basename $0) exit 1 fi cd / srcpath=. dstpath=quantum::sda1 date=`date "+%Y%m%d_%H%M%S"` rsync \ -aivxP \ --link-dest=../current \ $srcpath \ $dstpath/$date 2>&1
Notare che il --link-dest è relativo al percorso effettivo di backup
Ora si lancia il backup:
sudo /home/diesis/local/bin/timemachine-sda1