Quick and Easy Way to Backup Linux Directories to Another Server

No GoodNeed ImprovementOKGoodExcellent (No Ratings Yet)
Loading ... Loading ...

If you want to backup all directories under /home directory on server A to another server (server B), use the following script for automated batch backup:


#!/bin/bash

cd /home
for dir in $( ls )
do
if [ -d "$dir" ]; then
#echo $dir
tar czvf /disk2/$dir.tar.gz $dir
scp -P 22 /disk2/$dir.tar.gz backup@serverB.com:/backup
rm -rf /disk2/$dir.tar.gz
fi
done

You need to have a /disk2 directory for temporary tar.gz files.

You should create a public-private key pairs on server A and copy public key to server B, so you don’t need to enter password for automated backup (cron job).

Popularity: 1%

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word