How do I use Rsync to back up an Ispconfig website?

Procédure

What is Rsync?

Rsync is a command line file synchronisation program. It allows you to copy files from one place to another by synchronising them according to the source.

When your files are first backed up , Rsync will perform a full backup based on the source. It will then make partial backups of the data. In fact, it will only back up the source files that have been modified since the last backup.

How do you generate your RSA keys on ISPConfig?

1. Connect to your ISPConfig server using SSH and enter the following command:

$ ssh-keygen -t rsa -b 2048

When the keys are generated, they will be placed in the"/root/.ssh/id_rsa" folder on your private server.

Do not enter a passphrase, validate by pressing the"Enter" key on your keyboard. As soon as you enter a passphrase, it will be systematically requested so that you can connect to your remote backup space.

  • id_rsa: this is your private key, which must not be distributed.
  • id_rsa.pub: this is your public key.

2. Transfer the public key to your online backup space using the ssh-copy-id command.

$ ssh-copy-id -i /root/.ssh/id_rsa.pub user@remote_server
  • User: must be replaced by the relevant identifier
  • Remote_Server: must be replaced by the IP of the backup server

When you have validated the command, you will be asked for the user's password so that you can connect to the server and upload the"id_rsa.pub" file.

Setting up the online backup script with Rsync.

The script below will enable you to back up your data to your LWS online backup space.

1. Create the file sauvegarde.sh in the script folder:

nano /scripts/backup.sh

2. Copy and paste the script below and save your script by clicking on [CTRL] + [X].

#!/bin/sh day='date+%d-%B-%Y' log="/logs/" local="/public_html/" distant="/files/" hostssh="ip_serveur" userssh="login" echo "-------------------------------------------------------------" > $log/backup_$day.log # name of the backup in the log echo "Backup of $local on $(date +%d-%B-%Y)" >> $log/backup_$day.log echo "-------------------------------------------------------------" >> $log/backup_$day.log # transfer start time in log echo "Backup start time: $(date +%H:%M:%S)" >> $log/backup_$day.log echo "-------------------------------------------------------------" >> $log/backup_$day.log # file transfer rsync -az --stats -e ssh $local $userssh@$hostssh:$distant >> $log/backup_$day.log # -a : archive mode ( equivalent -rlptgoD ). # -z : data compression during transfer.
# -e : to specify the use of ssh # -- stats gives information about the transfer (number of files...). # --delete-after : deletes files which no longer exist in the source after transfer to the destination folder. status=$? echo "" >> $log/sauvegarde_$jour.log #error code rsync case $status in 0) echo Success >> $log/save_$day.log;; 1) echo Syntax or usage error >> $log/save_$day.log;; 2) echo Protocol incompatibility >> $log/save_$day.log;; 3) echo Errors when selecting files and input/output directories >> $log/sauvegarde_$jour.log;; 4) echo Action not supported: an attempt to manipulate 64-bit files on a platform that does not support them ; or an option that is supported by the client but not by the server. >> 5) echo Error starting client-server protocol >> $log/sauvegarde_$jour.log;; 6) echo daemon unable to write to log file >> $log/sauvegarde_$jour.log;; 10) echo I/O socket error >> $log/sauvegarde_$jour.log; 11) echo I/O file error >> $log/sauvegarde_$jour.log;; 12) echo Error in rsync protocol data stream >> $log/save_$day.log;; 13) echo Error with program diagnostics >> $log/save_$day.log;; 14) echo Error in IPC code >> $log/save_$day.log;; 20) echo SIGUSR1 or SIGINT received >> $log/save_$day.log;; 21) echo "An error returned by waitpid()" >> $log/save_$day.log;; 22) echo Error allocating main memory buffers >> $log/sauvegarde_$jour.log;; 23) echo Partial transfer due to an error >> $log/sauvegarde_$jour.log;; 24) echo Partial transfer due to the disappearance of a source file >> $log/sauvegarde_$jour.log;; 25) echo The --max-delete limit has been reached >> $log/sauvegarde_$jour.log;; 30) echo Maximum wait time exceeded when sending/receiving data >> $log/sauvegarde_$jour.log;; 35) echo Wait time exceeded while waiting for a connection >> $log/sauvegarde_$jour.log;; 255) echo Unexplained error >> $log/sauvegarde_$jour.log;; esac echo "-------------------------------------------------------------" >> $log/backup_$day.log # end time in log echo "Backup end time: $(date +%H:%M:%S)" >> $log/backup_$day.log echo "-------------------------------------------------------------" >> $log/backup_$day.log exit
  • IP_Server: must be replaced by the ip of your online backup formula
  • User: must be replaced by the username that has been managed for the online backup space.

How can I automate the backup script?

You can automate the backup by setting up a cron job. When setting up this task, you will need to indicate the location of your"backup.sh" file.

Conclusion

You can now set up an automatic backup of your ISPConfig server to an online backup space with LWS. You can define which files to include or exclude from your online backup.

Don't hesitate to share your comments and questions!

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

2mn reading

How do I add an RSA key to the Rsync SCP drive service?

1mn reading

How do I create a remote backup script with Rsync?

0mn reading

How do I back up my site with LWS Drive?

4mn reading

backup2l restore utility


Ask the LWS team and its community a question