Last update at :2024-01-09,Edit by888u
Restic is a very comprehensive backup tool that supports the most common backup methods such as Sftp and Rsync. At the same time, it not only supports local backup, but also supports backup to rclone mount, AWS and Google Cloud Storage, etc., which is very comprehensive.
This article simply takes Restic's Sftp backup method as an example to implement remote backup, and briefly introduces how to use Restic
A simple tutorial on the open source VPS backup software Restic
For the convenience of the following discussion, this article assumes that we now want to back up the data of server A to server B
Operations on server A:
1. Download software
Download the binary file of the latest version of Restic (no need to compile, use it directly): the latest address can be viewed at https://github.com/restic/restic/releases/latest. This article uses 64-bit software as an example
wget https://github.com/restic/restic/releases/download/v0.9.4/restic_0.9.4_linux_amd64.bz2 #You may need to use apt-get or yum to install bzip2 for the next step of decompression bzip2 -d restic_0.9.4_linux_amd64.bz2 chmod +x restic_0.9.4_linux_amd64 #Move to the system program directory mv restic_0.9.4_linux_amd64 /usr/local/bin/restic #View version restic version #Self-upgrade (optional operation) restic self-update2. Create SSH login key
cd ~ ssh-keygen-trsa #You need to select Enter or Y several times, choose according to the actual situation cat ~/.ssh/id_rsa.pub #Copy the information shown above for later useOperation on server B:
#Do not remove the English single quotes below echo 'The content of id_rsa.pub just now' >> ~/.ssh/authorized_keysOperations on server A:
Create a backup warehouse (the warehouse directory in this article is set to /home/vmvps). B.B.B.B is the IP of server B. You need to wait for a while and then enter the password twice. Note that the password must be remembered! It will be used when backing up, restoring and viewing data in the future
restic -r sftp:root@B.B.B.B:/home/vmvps initBack up the /home/backup folder of server A to the /home/vmvps backup warehouse of server B. B.B.B.B is the ip of server B
#You need to enter the password you just created when you created the backup warehouse restic -r sftp:root@B.B.B.B:/home/vmvps --verbose backup /home/backupView backed up files
restic -r sftp:root@B.B.B.B:/home/vmvps snapshotsReturn results similar to
enter password for repository: repository dfc03097 opened successfully, password is correct ID Time Host Tags Paths -------------------------------------------------- ------------------ 3ddabe77 2019-02-26 02:36:32 ing /home/backup -------------------------------------------------- ------------------ 1 snapshotsDelete backup files
restic -r sftp:root@B.B.B.B:/home/vmvps forget ID of the file to be deletedRestore backup
restic -r sftp:root@B.B.B.B:/home/vmvps restore abcd --target /home/backupPassword-free operation of storage warehouse
As mentioned before, our storage warehouse password will be used almost at any time. This makes it very difficult when we want to implement automated script backup. We can save the password to a file ( Be sure to keep it properly) and add parameters to solve this problem
#Assume the password here is vmvps and save it to the file /root/resticpasswd echo 'vmvps' > /root/resticpasswdIn this way, you can add the –password-file /root/resticpasswd parameter during operation to achieve the purpose of eliminating passwords. For example, you can use the following command during backup and add it to crontab to achieve automatic backup
restic -r sftp:root@B.B.B.B:/home/vmvps --verbose backup /home/backup --password-file /root/resticpasswd
Recommended site searches: free virtual space, vps virtual host, website server rental, US server rental, virtual host space icp fast registration, Taiwan proxy server, overseas server, large bandwidth server rental, overseas virtual host,
发表评论