RSYNC – simply clone an entire system ?
To clone an entire system, we will execute rsync with options to :
- recurse directories
- preserve permissions, owner and group
- preserve soft and hard links
- preserve devices (/dev directory)
- ignore times, so that ‚newer’ files on target system will get modified to mach those on the model
- reset timestamps, so that next replications can ignore files that are ‚newer’
- exclude the copying of running processes
- show progress, because it’s a lenghty proces. You can also add -v for verbose to just get a list of files being processed
On a clean, fresh installed system, run
rsync -vrpoglHDIt --rsync-path="nice rsync" --exclude=/proc --progress remotemodel:/ /
which will make every file on the new system identical to the remotesystem. Could be tricky re. hostnames and ip configuration, and you have to be pretty sure the hardware of both machines is identical (because you’re also cloning the kernel image, hardware-specific modules, and so on). What you do is actually replacing a running system – by copying another running system. Ain’t that cool.
So image you create 1 model configuration. Then, install Linux on as many PC’s as you require. The configuration does not matter much so this can easily be automated, although it helps if the configuration is already close to the model : rsync only transfers the difference between the machines. Then, rsync the pc’s with the model, using the rsync options shown earlier. The pc’s will become exact copies of the model. You may want to change some things (everything that needs to be unique), then reboot. Finished.
Synchronising running systems
When you add an rsync statement in a cron job or startup script, the ‚clones’ will synchronise at regular intervals and / or everytime they reboot (or when a user logs on). By choosing the directories that need to be synchronised, you can avoid trouble with duplication of values that need to remain unique.
As rsync only transfers differences, this is a nice way to transfer modified configuration files : just edit the config on the model machine, and wait for the others to synchronise. Also works for software distribution : install packages on the model, and configure them. When synchronising, all added files and modifications to existing files will be replicated to the clones. And it can be done while they’re online …
As only changes will be processed, you can use the same rsync statement (without -v and –progress, with -q for quit) : you’ve started with a synchronised system, and only subsequent changes will be transferred, or you can fine-tune it a bit, eg like so:
rsync -rpoglHtu --rsync-path="nice rsync" --exclude=/proc --exclude=/tmp --exclude=/sys remotehost.com:/ /
-r, –recursive recurse into directories
-p, –perms preserve permissions
-o, –owner preserve owner (super-user only)
-g, –group preserve group
-l, –links copy symlinks as symlinks
-H, –hard-links preserve hard links
-t, –times preserve modification times
-u, –update skip files that are newer on the receiver
-q, –quiet suppress non-error messages
- refer to earlier example
- do not overwrite newer files on target (= do not undo changes made by users)
- multiple exclude paths for irrelevant directories
- run quiet