Automated Backup via Rsync, Tar and SCP
In the previous article, I have discussed about synchronizing data with rync. In this article I will continue the topic to a new discussion: how to use rsync for automated backup. Here are the scenarios that I use in this article:
There are 3 servers (Server1, Server2, Server3) that have data in it and need to be backed up daily to a backup server (Backupsvr) in directory /backups. I will use a user account named backupusr on backupsvr. The backupusr have full control access to directory /backups. I will prepare the public/private key pair for backupusr and use it for key-based authentication. For the backup process, I will use these three steps:
1) Use rsync to back up data in each server in to a separate directory in the each local server. By doing this, each server will have backup copy of its data in separate directory that can be restored quickly and easily when needed.
2) Create a compressed archive file of backed-up directory for offsite transfer. This process will create a compact file that can be easily transfer offsite.
3) Transfer the compressed archive file to the backupsvr using SCP. In this step, I will use key-based authentication for SCP.
Here are the detail steps :
Preparing the public/private dsa key pair and place the private key in backupsvr and distribute the public key the server-server.
In Server1
1. Create user account backupusr. I will use this user account to generate public/private dsa key pair.
[root@server1 ~]# useradd backupusr
[root@server1 ~]# passwd backupusr
Changing password for user backupusr.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@server1 ~]#
2. Generate public/private dsa key pair for user backupusr. I will create key pair called identity (identity and identity.pub) in backupusr home directory with null-passphrase.
[root@server1 ~]# su - backupusr
[backupusr@server1 ~]$ ssh-keygen -f identity-backupusr -t dsa -N ""
Generating public/private dsa key pair.
Your identification has been saved in identity-backupusr.
Your public key has been saved in identity-backupusr.pub.
The key fingerprint is:
26:e3:55:7a:fd:0f:e8:a6:5c:52:bf:a4:eb:bc:69:cd [email protected]
[backupusr@server1 ~]$
3. Copy the identity file to root home directory. Copying this private key file is to make it easier for root to access the file.
[backupusr@server1 ~]$ exit
[root@server1 ~]# cp /home/backupusr/identity-backupusr .
In Backupsvr
1. Create user account backupusr.
[root@backupsvr ~]# useradd backupusr
[root@backupsvr ~]# passwd backupusr
Changing password for user backupusr.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
2. Create directory /backups and give permissions only to the backupusr
[root@backupsvr ~]# mkdir /backups
[root@backupsvr ~]# chown backupusr.backupusr /backups
[root@backupsvr ~]# chmod 700 /backups
3. Log on as backupusr in Backupsvr, create .ssh directory and copy the identity-backupusr.pub (public key) from Server1, copy the identity-backupuser.pub file to .ssh/authorized_keys file and change the permissions.
[backupusr@backupsvr ~]$ scp [email protected]:identity-backupusr.pub .
The authenticity of host 'server1.mydomain.com (1.2.3.2)' can't be established.
RSA key fingerprint is 8d:35:1e:e4:1a:87:26:9a:b0:96:c3:5d:cd:1b:c1:ed.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server1.mydomain.com' (RSA) to the list of known hosts.
backupusr@backupsvr's password:
identity-backupusr.pub 100% 615 0.6KB/s 00:00
[backupusr@backupsvr ~]$ cat identity-backupusr.pub >> .ssh/authorized_keys
[backupusr@backupsvr ~]$ chmod 700 .ssh
[backupusr@backupsvr ~]$ chmod 700 .ssh/authorized_keys
In Server2
1. Copy the identity file (private key file) from Server1 to root home directory in Server2.
[root@server2 ~]# scp [email protected]:identity-backupusr .
The authenticity of host 'server1.mydomain.com (1.2.3.2)' can't be established.
RSA key fingerprint is 8d:35:1e:e4:1a:87:26:9a:b0:96:c3:5d:cd:1b:c1:ed.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server1.mydomain.com' (RSA) to the list of known hosts.
backupusr@server1's password:
identity-backupusr.pub 100% 615 0.6KB/s 00:00
[root@server2 ~]#
2. Test the connection from Server2 to Backupsvr using key-based SSH authentication. If login no longer requires a password, then the key-based ssh authentication is working.
[root@server2 ~]# ssh –i identity-backupusr backupsvr.mydomain.com
[backupusr@backupsvr ~]$
In Server3
1. Copy the identity file (private key file) from Server1 to root home directory in Server3.
[root@server3 ~]# scp [email protected]:identity-backupusr .
The authenticity of host 'server1.mydomain.com (1.2.3.2)' can't be established.
RSA key fingerprint is 8d:35:1e:e4:1a:87:26:9a:b0:96:c3:5d:cd:1b:c1:ed.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server1.mydomain.com' (RSA) to the list of known hosts.
backupusr@server1's password:
identity-backupusr.pub 100% 615 0.6KB/s 00:00
[root@server3 ~]#
2. Test the connection from Server3 to Backupsvr using key-based SSH authentication. If login no longer requires a password, then the key-based ssh authentication is working.
[root@server3 ~]# ssh –i identity-backupusr backupsvr.mydomain.com
[backupusr@backupsvr ~]$
In Server1
1. Test the connection from Server1 to Backupsvr using key-based SSH authentication. If login no longer requires a password, then the key-based ssh authentication is working.
[root@server1 ~]# ssh –i identity-backupusr backupsvr.mydomain.com
[backupusr@backupsvr ~]$
The next step is to create the backup script file and schedule it.
In Server1
Prepare the backup script
[root@server1 ~]# vi /backups/backup.sh
#!/bin/bash
EXT_BACKUP_PATH=”[email protected]:/backups”
INT_BACKUP_PATH=”/backups”
DIRS=”/data /home”
weekday=`date +%a`
shorthostname=`hostname -s`
# Backup to local directory
rsync -avHK –delete $DIRS $INT_BACKUP_PATH/$weekday
# Create archive of backed-up directory for offsite transfer
tar -zcvf $INT_BACKUP_PATH/$shorthostname.$weekday.backup.gz $INT_BACKUP_PATH/$weekday
#Transfer archives file to the backup server
scp -i /root/identity-backupusr $INT_BACKUP_PATH/$shorthostname.$weekday.backup.gz $EXT_BACKUP_PATH
Then make the file executable and scheduled the script. In this scenario, I scheduled the script to run every night using cron.
[root@server1 ~]# chmod +x /backups/backup.sh
[root@server1 ~]# crontab –e
@daily sh /backups/backup.sh
Then create the same script for server2 and server3 then scheduled the script.
Note: you can refer to an article about crontab if you want it to run at other times.
In Server2 and Server3
Create the backup script (or copy it from server1) then schedule it
When the scheduled time comes, the server will backup the data via rsync, archive the backed up copy then transfer the archive file to the backup server.
August 15th, 2023 at 4:08 am
order tricor 160mg generic buy tricor 160mg pill buy tricor pills for sale
August 19th, 2023 at 4:47 am
purchase ketotifen without prescription buy doxepin pills for sale buy tofranil 75mg online
August 19th, 2023 at 11:06 pm
buy generic cialis 10mg sildenafil 50mg order sildenafil 100mg pill
August 22nd, 2023 at 1:58 am
acarbose 25mg without prescription griseofulvin 250 mg ca fulvicin sale
August 22nd, 2023 at 1:48 pm
buy mintop generic minoxytop price best ed medications
August 25th, 2023 at 4:04 am
order aspirin 75 mg online cheap buy generic zovirax buy zovirax sale
August 26th, 2023 at 8:09 pm
order dipyridamole online dipyridamole online pravachol 20mg ca
August 28th, 2023 at 3:26 pm
buy melatonin online brand danazol order danazol 100 mg for sale
August 30th, 2023 at 11:50 pm
purchase florinef pills fludrocortisone 100mcg pill imodium 2mg sale
August 31st, 2023 at 5:54 am
brand duphaston order empagliflozin 10mg pills buy generic jardiance online
September 3rd, 2023 at 12:08 am
buy prasugrel pills how to buy tolterodine order tolterodine sale
September 4th, 2023 at 1:30 am
etodolac 600mg drug etodolac 600 mg drug cost pletal
September 6th, 2023 at 12:56 am
ferrous 100 mg pill generic actonel 35 mg order betapace 40mg pills
September 8th, 2023 at 12:13 pm
order mestinon 60 mg maxalt online order rizatriptan 10mg over the counter
September 9th, 2023 at 1:13 am
enalapril 5mg pill lactulose tubes order generic lactulose
September 12th, 2023 at 12:49 am
betahistine 16mg oral betahistine cost probalan over the counter
September 12th, 2023 at 3:35 pm
generic zovirax order exelon 6mg without prescription order rivastigmine
September 14th, 2023 at 4:05 am
prilosec 20mg ca omeprazole 20mg over the counter buy generic metoprolol 50mg
September 14th, 2023 at 7:53 pm
brand premarin cost viagra sildenafil without a doctor’s prescription
September 16th, 2023 at 12:04 am
buy generic telmisartan for sale brand molnupiravir 200mg molnunat order online
September 17th, 2023 at 12:04 pm
oral cenforce 100mg buy cenforce no prescription chloroquine 250mg usa
September 17th, 2023 at 10:21 pm
buy tadalafil online cheap order cialis pills sildenafil for sale
September 20th, 2023 at 9:01 am
oral cefdinir 300mg cefdinir pill cheap lansoprazole
September 21st, 2023 at 9:52 am
provigil 200mg generic prednisone generic prednisone 40mg pills
September 23rd, 2023 at 7:39 pm
order isotretinoin 20mg generic zithromax 500mg pills purchase azithromycin sale
September 24th, 2023 at 2:17 pm
order lipitor 20mg for sale order amlodipine pills norvasc pills
September 26th, 2023 at 2:55 am
order azithromycin 250mg cost azipro 500mg buy gabapentin medication
September 27th, 2023 at 11:55 pm
pantoprazole 40mg for sale pyridium order online phenazopyridine 200 mg tablet
September 28th, 2023 at 3:14 am
casino slot free buy furosemide 40mg without prescription order lasix 40mg generic
September 29th, 2023 at 8:39 pm
play online blackjack doxycycline 100mg over the counter ventolin 4mg sale
October 1st, 2023 at 3:38 am
symmetrel 100 mg price buy generic amantadine 100 mg dapsone 100 mg pills
October 1st, 2023 at 12:01 pm
online poker real money stromectol oral ivermectin canada
October 2nd, 2023 at 4:33 pm
Heya! I’m aat work browsing our blog froom mmy new apple iphone!
Jusst wanted tto saay I loe reading our bloog and liok forward tto alll yoiur posts!
Carry on tthe great work!
October 3rd, 2023 at 5:10 am
online money poker synthroid drug buy levothyroxine pills for sale
October 4th, 2023 at 1:41 am
buy medrol pills for sale nifedipine tablet triamcinolone 10mg cheap
October 4th, 2023 at 7:18 pm
purchase clomid generic buy imdur medication buy azathioprine medication
October 6th, 2023 at 9:30 am
buy vardenafil pills for sale generic vardenafil 20mg tizanidine online
October 6th, 2023 at 8:48 pm
aceon 4mg without prescription clarinex 5mg over the counter buy fexofenadine pills for sale
October 8th, 2023 at 10:19 am
dilantin canada order generic flexeril 15mg purchase ditropan
October 9th, 2023 at 10:51 pm
order loratadine 10mg online cheap purchase dapoxetine without prescription dapoxetine where to buy
October 10th, 2023 at 12:01 pm
order ozobax for sale endep 10mg uk how to buy toradol
October 12th, 2023 at 4:47 am
baclofen 10mg canada buy ketorolac pills for sale purchase toradol sale
October 12th, 2023 at 8:39 pm
amaryl brand glimepiride sale purchase etoricoxib
November 3rd, 2023 at 10:36 pm
60mg priligy Afterwards, the Duke of Bavaria led his troops to pursue it, expanded the land for hundreds of miles, and plundered three cities, Roger smiled, Said There are no shortcuts to magic training, But it shouldn t take four dollar blood pressure medicine at walmart long, I should be a tenth level mage, I will let you experience the harm of decomposition