Lazy Geek -:)
Automatic backup from Ubuntu Server with Rsync
Scenario:
2 Ubuntu Server: 1 is named as tendo-Srv with an ip address of 192.168.1.190, from which we want to take backup and 1 is named as tendo-backup with an
ip address of 192.168.1.177, on which we want to place our backup. But we want all this process automatic, at a defined time/ interval.
Generate the ssh key pair on tendo-Srv:
ssh-keygen
Copy the public key to the tendo-backup:
Follow
scp ~/.ssh/id_rsa.pub [email protected]:
Connect to the tendo-backup:
ssh [email protected]
Append the public key to authorized_keys:
cat id_rsa.pub >> ~/.ssh/authorized_keys
We got an error saying “~/.ssh/authorized_keys: No such file or directory” it means that there is no .ssh directory for this user (this user has never used ssh
before). Simply create an empty .ssh directory with 700 permissions:
mkdir ~/.ssh
chmod 700 ~/.ssh
Now,try to append the public key to authorized_keys once again:
cat id_rsa.pub >> ~/.ssh/authorized_keys
Remove the uploaded copy of authorized_keys:
rm id_rsa.pub
Follow
Edit the ssh server configuration:
sudo nano /etc/ssh/sshd_config
Make sure that public key authentication is enabled (it should be enabled by default), these entries must be set to yes also:
RSAAuthentication yes
PubkeyAuthentication yes
Reload the ssh configuration:
sudo service ssh reload
Create a directory,where we want to keep the backup on tendo-backup server and set a permission on it:
sudo mkdir /backup
sudo chown arbab:arbab /backup/
Disconnect from the tendo-backup:
exit
Try to connect to tendo-backup server again, and this time, it will not ask for the password
ssh [email protected]
Follow
Create a separate directory and file, where we want to keep the rsync log on tendo-Srv and set the permission on it as well:
sudo mkdir /rsynclog
sudo touch /rsynclog/rsynclog.log
sudo chmod 0777 /rsynclog/rsynclog.log
Now, copy the files from tendo-Srv to tendo-backup with Rsync:
rsync -e ssh --progress --partial --delete -avz --log-file=/rsynclog/rsynclog.log /data/ [email protected]:/backup
Where /data/ is a directory on local server(tendo-Srv) and /backup/ is directory on remote server(tendo-backup) & rsynclog.log is a log file at /rsynclog
location, where it will save the log every time after execute the command.
Check the log file:
cat /rsynclog/rsynclog.log
Check the backup on the tendo-backup server:
cd /backup/
ls
Edit the Cron file (Special thanks to Fernando Flores, to correct the syntax of this command):
sudo crontab -user arbab -e
Follow
We need to configure it in such a way that it automatically take the backup at 8 p.m. everyday:
00 20 * * * rsync -e ssh --progress --partial --delete -avz --log-file=/rsynclog/rsynclog.log /data/ [email protected]:/backup
Hope this will help you!
Please Remember me in your prayers!
Name (required)
Email (required)
Website
Comment (required)
Submit »
Rate this:
1 Vote
Share this:
Twitter Facebook 5 LinkedIn 1 Print More
Like
Be the first to like this.
Related
File Synchronization Between Two Public-Key Authentication in SecureCRT Part-1: Creation of Hard drive image
Ubuntu Servers using Unison using Clonezilla
Linux, Ubuntu automatic backup, Automatic backup from Ubuntu Server with Rsync, backup, backup server, backup with rsync, rsync, ssh server,
ubuntu backup
Follow
← Mikrotik as Gateway Configure Mikrotik DHCP to assign ip address to only authorized client(s) →
Blog at WordPress.com. The zBench Theme. ↑ Top
Follow