Doc /

Complete backup of a server

A data or web server needs several kinds of backups, depending what problem the backup is aimed to fix.

D'un serveur à l'autre (openSUSE)

Comme root, pour sauvegarder la racine du serveur (2022):

# rsync -azv -e ssh -x --exclude=/tmp --exclude=*cache* --exclude=*.Trash* --exclude=/run --delete  root@<source domain>:/ <local folder>

/sys /proc sont des points de montage, exclus par -x

Du web vers un disque local

rsync -azv -e ssh --delete --exclude=/tmp --exclude=*cache* --exclude=*.Trash* <user@nom-domaine>:/home/<user>/ /<point-de-montage-du-disque>/<repertoire>/

Il faudra donner un mot de passe si le lien ssh n'est pas permanent.

Backup from a date

time find . -type f newermt 2012-01-01 ! -newermt 2017-01-01 -print0 | rsync -HAXaxi --delete --from0 --files-from=- . /run/media/jdd/0ae3a54f-b032-4a21-8180-14d5efc5577f

Local backups

Backing up, or better said archiving with large usb disks is a good idea.

Better mount the source disk as read only, in my case better do as user as I'm the only user of this computer, so all the files are owned by me. See Mount a disk as user, read only.

After that (and only after that), plug or switch on the target disk and mount it read/write.

Then

rsync -av --delete /run/media/jdd/intenso5to2/ /run/media/jdd/intenso4to/

with the right mount points. Preferably usb3! And wait.

I sometime change some folder names. If I remember this on time, it's better to do the same manually on the target, else the old folder will be removed and replaced, but it may be longer.

Rsync scripts and ssh

Most backups are done with rsync scripts, preferably to an external server (other than the one being backed). So you may need to setup a ssh authentification key without pass phrase to connect the two computers (see).

and with cron:

 MAILTO = jdd@dodin.org
 30 01 * * * /root/bin/backup-to-kim7.sh

in the script script, two lines:

rsync -azv --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" /home/ kim5@kim7.dodin.org:/home/kim5/backup/home/
rsync -azv --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" -x / kim5@kim7.dodin.org:/home/kim5/backup/system/

Home

By home, I mean home and all the eventual data, I mostly try to setup data folders in /home for convenience (in the server). There are probably in /home no special file needing special treatment, but the files may be large or in large number. These files mostly have to survive a server upgrade.

rsync -avz --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" /home user@dodin.org:~/data/

fake-super is there to keep superuser permissions if any.

save it in a script bash in bin

In cron:

 30 01 * * * /root/bin/backup-home

System

In system, the key is "-x' that mean "no external file system", for example do not go to mounted parts (so no /home) nor extra file systems like /dev or /proc.

rsync -avz --delete --rsync-path="rsync --fake-super"   -e "ssh -i /root/.ssh/id_dsa" -x / nemo-bk@dodin.org:/data/nemo-bk/system

Restore

If using fake-super, this option have also to be used at restore time. Si vous utilisez --delete, soyez très prudent quand au répertoire où vous faites la restauration, ici le répertoire wordpress. Le "." à la fin de la commande signifie que vous devez vous trouver dans ce répertoire pour la lancer!

 rsync -avz --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" kim5@kim7.dodin.org:/home/kim5/backup/home/data/srv/www/htdocs/wordpress/ .

Variants

rsync -av --max-size=400m --delete --exclude=/media --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/var/tmp --delete-excluded --exclude='*/Cache/*' --exclude=/windows/C/pagefile.sys / /media/opensuse11/

ajouter "-n" (dry run) au premier essai

sauvegarde du serveur:

rsync -av --exclude=/media --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/var/tmp --exclude=/data --exclude=/extra --exclude=/home / .

-e ssh root@dodin:/ pour passer par ssh

attention, ca exclu /data

pour les données:

rsync -av --exclude k2_root/ --exclude backup/ -e ssh root@dodin.org:/data/ .

Usage de l'option "-x" (one file system)?

se placer dans le répertoire de réception et

rsync -av -x --delete origine destination

Sauvegarde du serveur du culte:

m-r (dans m-r, script cron):

rsync -avz -e "ssh -i /root/.ssh/id_dsa" / cu1lt2@dodin.org:/data/culte-serveurs-bk/m-r/ --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/var/tmp --delete-excluded --exclude='*/Cache/*' --max-size=400m --delete