Rsync is a marvelous if somewhat intimidating file-synchronization tool. I've been using it with good results to upgrade embedded linux devices in the field. (We have a backup kernel and root filesystem partition, so this is not a crazy as it sounds.)
Rsync is one of those programs that can do some many things that it is sometimes easier to modify an example what you want to do rather than trying to figure it out from the man page. So here are two examples.
Say we have a directory newroot that contains an image of the root file system we want to apply to a remote system:
Upgrade Root Filesystem Using Rsync
If we want to replace an entire root filesystem we can do it like this:
rsync -RlptzvPDe "ssh -i ~/.ssh/id.rsa" --checksum --delete --stats --exclude="sudo" --exclude="sudoedit" --exclude="shadow" --exclude="gshadow" newroot/bin newroot/etc newroot/lib newroot/sbin newroot/opt newroot/usr newroot/var/lib newroot/www newroot/boot firstname.lastname@example.org:/
switches controlling what to copy: (r)ecursive and recreate (l)inks
switches controlling metadata: (p)ermissions (t)ime but not (D)evices (g)roup (o)wner (as we want ssh user to own everything)
other required switches: (z)compress (e)xecute-via-ssh --checksum (slower but safer)
other useless switches: (P)rogress (v)erbose --stats
Specifying the root source directories (/bin, /etc...) avoids problems associated with the special directories like /proc and /dev.
Note I am using the not-particularly-safe --delete option. That is one reason why syncing special directories would be unwise.
The excludes are there to prevent attempts to overwrite a couple of other files associated with authentication.
Upgrade Multiple Files Using RsyncSay you just need to send a couple of files. Rsync is very fast even when asked to duplicate the entire root filesystem, but sometimes the root filesystem built by the cross-compiling toolchain defers constructing the startup script order until first boot. Upgrading everything restores the system to first boot configuration, with the result that a checkconfig script might run to reconstruct the various scripts in /etc/rcS.d. That is unnecessary if none of that is actually changing.
Here's how to upgrade a few selected files (myApp and myApp.conf) using rsync:
rsync -RlptzvPDe "ssh -i ~/.ssh/id.rsa" --checksum --stats newroot/./etc/myApp.conf newroot/./opt/myApp email@example.com:/
Here we've used (R)elative paths instead of (r)ecursive. Identifying the part of the relative path you want to transfer with a "." is a trick from the rsync manual; it means "copy relative path starting here." Since the target is / we end up upgrading files in /etc and /opt on the remote.
One issue: it seems rsync cannot upgrade itself via rsync!