Backup incrementale completo su NAS con Rsync
Da MontelLUG WIKI.
Versione del 5 ott 2013 alle 22:50 di Odeeno (discussione | contributi) (Creata pagina con '= Script per un backup incrementale con Rsync = <pre> #!/bin/bash # # A backup script based on Rsync that pushes backups onto a NAS # # Directories are rotated n times and ...')
Script per un backup incrementale con Rsync
#!/bin/bash # # A backup script based on Rsync that pushes backups onto a NAS # # Directories are rotated n times and rsync is called to # place a new backup in 0.backups_ago/ # # Fonte http://netcodger.wordpress.com 4/17/2012 # Personalizzazioni mie # # Edit these variables to suit your environment n=X #;Number of backups to retain NAS=192.168.1.XXXX #;IP address or resolvable hostname of NAS SrcDir=/home/ciccio #;Directory to be backed up DestDir=/shares/ciccio #;Backup destination on NAS # End of edits clear echo echo ========================================================================= echo Avvio del programma di backup; date; echo # Delete the n’th backup. echo echo ========================================================================= echo Rimozione del più vecchio backup e rinomina di tutti i successivi; date; echo ssh nome@$NAS "[ -d $DestDir/$n.backups_ago ] && rm -rf $DestDir/$n.backups_ago " # Rename backup directories to free up the 0.backups_ago directory ssh nome@$NAS "for i in {$n..1}; \ do [[ -d $DestDir/"'$(($i-1))'".backups_ago ]] && \ /bin/mv $DestDir/"'$(($i-1))'".backups_ago $DestDir/"'${i}'".backups_ago; done" # Run the Rsync command. Nice is used to prevent Rysnc from hogging the CPU. # –link-dest creates hard links so that each backup run appears as a full # backup even though they only copy changed blocks since 1.backups_ago echo echo ========================================================================= echo Avvio del backup; date; echo nice rsync -av --stats --progress \ --partial --partial-dir=$DestDir/.rsync-partial \ --link-dest=$DestDir/1.backups_ago \ --delete-after --delete-excluded \ --exclude=Trash* \ --log-file=$SrcDir/backup.log \ $SrcDir nome@$NAS:$DestDir/0.backups_ago/ # altre opzioni utili --compress (equivalente -z) --list-only echo echo ========================================================================= echo Completed running backup.sh; date; echo echo exit # Per evitare l'inserimento della password di nome ad ogni avvio del programma # e ogni volta che viene lanciato ssh dallo script è consigliabile generare # una chiave privata ed effettuare lo scambio. # # ssh-keygen -t rsa (non inserire password) # ssh nome@MyBookLive mkdir -p .ssh # cat .ssh/id_rsa.pub | ssh nome@192.168.1.XXX "cat >> .ssh/authorized_keys" # ssh nome@MyBookLive # nas:~# chmod -R go-rwx .ssh # nas:~# exit#