Using rsync for secure remote backups

rsync can be used locally or over the network. It supports ssh, for secure remote differential backups.

General usage:rsync -e ssh -avz src_path username@hostname.com:dst_path
e.g.:rsync -e ssh -avz /etc/ root@myserver.com:/etc/
To delete files that are on the destination system but no longer on the source system, use the --delete option:

e.g.:rsync -e ssh -avz --delete /lib/ root@myserver.com:/lib/
Here's the full meal deal for doing a total system backup. This will completely duplicate one system onto another, over the Internet. Make sure the hardware, boot devices, etc are the same or you're in for trouble:rsync -e ssh -avz --stats --progress --delete-after --exclude-from=/root/rsync-exclude / root@myserver.com:/
Note that "/root/rsync-exclude" should include things like:dev/tmp/proc/var/lock/var/run/

Comparing directories

You can use rsync to show differences between two directories without changing anything. In the following example, your /home/myuser is compared with the same folder on computer target:rsync -e ssh -avz --delete --dry-run /home/myuser root@target:/home
This comparison only considers timestamps and file sizes. For comparing directories based on content, use other programs, e.g. krusader.

Inkrementális mentés

Forrás

Inkrementális mentés példa
#!/bin/bash
#Backup Script

#Mai nap ISO-8601 formátumban:
DAY0=`date -I`

#Egyéb napok ISO-8601 formátumban:
DAY7=`date -I -d "7 days ago"`
DAY28=`date -I -d "28 days ago"`

#Menteni kívánt mappa elérése
SRC="/home/david/dir1"

# Mentés helyének megadása
TRG="/home/david/dir2/$DAY0"

#Link helyének megadása
LNK="/home/david/dir2/$DAY7"

#rsync beállítás:
OPT="-avh --delete --link-dest=$LNK"

#rsync inkrementális mentés, linkmegadással.
rsync $OPT $SRC $TRG

#Valtozok
dir2="/home/david/dir2"
dir3="/home/david/dir3"

#28 nappal ezelőtti inkrementális mentések törlése
if [ -d $dir2/$DAY28 ]
then
rm $dir2/$DAY28
fi

#28 naponta "havi" mentés

if [ ! -f $dir2/$DAY7 ]
then 
rsync -avh $SRC $dir3
else if [ -d $dir3/$DAY28]
then 
rsync -avh $SRC $dir3
fi
fi - See more at: http://rendszerinformatika.hu/bootcamp/rsync-inkrementalis-mentes/#sthash.fAH52nVQ.dpuf
  • No labels