Preamble
As a Linux System Administrator, I've had to keep two servers in synchronization, either nightly or every couple of hours. The term is 'mirror' and can be seen in use when downloading Ubuntu .iso files from localized servers, say from a Cambodian server when the main server is in Britain. (You may not know this, but that's how it works, using pretty much the same script you see below).
Why should I use this script?
You don't have to be a Linux System Administrator to enjoy the beautiful interoperability benefits of Linux, you can put it to use right at home!
Use this script to backup your entire family's data, every night, by using a central server and making the server 'pull' everyone's documents to it.
How do I use this script?
How? Well if you purchase a 500GB server, then you could potentially backup five family member's computers if they each had a 100GB hard drive.
Simply use this script with the 'install' argument five times on the server and it will create five keys, one for each of your family members.
You need to setup either DNS names for the computers or static IP addresses for each computer.
I won't go into great detail on how to do this in every situation, but for a home network, you can change the IP address of one of your computers to a static IP address like this:
Code:
gksu gedit /etc/network/interfaces
Before:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
After:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.10 # computer1 = 192.168.1.10, computer2 = 192.168.1.11, computer3 = 192.168.1.12, etc.
netmask 255.255.255.0
gateway 192.168.1.1
As for the Linux System Administrators, I don't need to tell you how useful this script is
Any alternatives?
Of course! I'm not the first person to need file-synchronization or mirroring, but I feel most comfortable writing my own scripts so I know what's going on and can control the encryption strength.
GUI (Graphical User Interface)
unison: a file synchronization program used to sync files between two directories, either on one computer, or between a computer and another storage device. (I've never used it, but I heard its reliable)
Code:
sudo aptitude install unison unison-gtk
CLI (Command Line)
rsnapshot: a filesystem snapshot utility for making backups of local and remote systems. The disk space required is just a little more than the space of one full backup, plus incrementals. (My program does not use incrementals).
Code:
sudo aptitude install rsnapshot
Vocabulary
- ssh: a network protocol that allows data to be exchanged using a secure channel (encryption) between two computers
- rsync: a software application for Linux which synchronizes files and directories from one location to another using minimal bandwidth (only transfers files (or parts of files) that don't exist)
- mirror: an exact copy of a data set
- push: to send (or give) data from one computer to another
- pull: to receive (or ask) for data from one computer to another
Let's get started
It has several flags and options, but some are hard-coded, so you may have to edit the script by hand.
Options
General usage:
./rsync.sh ['uninstall' | 'install' | 'run'] ['push' | 'pull'] [local_dir] [remote_user] [remote_host] [remote_dir] [remote_ssh_port]
Note: '[remote_ssh_port]' is usually 22 unless you change it from the default. If you don't know how to change the ssh port, its more than likely 22.
install
Use this option if you want to setup an automated, nightly backup between one computer and another.
Arguments:
./rsync.sh install [push | pull] [local_dir] [remote_user] [remote_host] [remote_dir] [remote_ssh_port]
Example:
./rsync.sh install pull /home/brett/ brett 192.168.1.2 /home/brett 2222
- Creates the following directories: $HOME/bin, $HOME/cron, $HOME/logs
- Creates 4096-bit RSA encryption key (illegal in the USA I think)
- Installs file to directories above
uninstall
Use this option if you want to remove a previously installed setup.
Arguments:
./rsync.sh uninstall [remote_user] [remote_host]
Example:
./rsync.sh uninstall brett 192.168.1.2
- Removes cron-job
- Removes RSA key
run
Use this option if you want to run the program without installing anything. Good to use as a test and on a single-needs basis.
Arguments:
./rsync.sh run [push | pull] [local_dir] [remote_user] [remote_host] [remote_dir] [remote_ssh_port]
Example:
./rsync.sh run pull /home/brett/ brett 192.168.1.2 /home/brett 2222
- Runs rsync with your parameters
rsync.sh
http://github.com/brettalton/rsync-o...aster/rsync.sh
Bookmarks