During academics, we have heard so many times about backups. In offices we have costly utilities to do such stuff too, but when it comes to personal data on laptops / desktops, we need something which can make our backup process better. After all we’ll be backing up large files music & movies too.
In this issue of command line gyan, we’ll see how we can use command line utilities to sync our folder locations and backup effectively. Although we talk about backup, this can be used for multiple activities as per user choice
So far the best know utility in Linux to sync data is RSYNC
The best part with rsync is that it allows copy recursively within one machine and even remote machines as well.
As the name suggests, it’s a sync utility which means will copy only the changes and not the whole file and it also maintains file ownership and permissions
The usage is pretty simple
$ rsync [options] source destination
$ rsync -arH /home/clubhack/ /mnt/backup
I commonly use arH options helps archiving the data (the a bit), does it recursively including subdirectories & maintains the hardlinks
Now if you want to use the same rsync to transfer file on remote machine, the best option would be
$ rsync -aH /my_dir/ remoteIP:/path/to/dir/
To preserve permissions, ownership, group & timestamp you can choose to use switches like -p, -o, -g, -t etc.
You can even choose which files to be included or excluded in your syncing.
I’d strongly urge you to go ahead and check the man page of rsync. If you are not using it, you are missing something very important.
For windows environment till XP we haven’t seen any such wonderful utility inbuilt.
Although commands like copy & xcopy are there but they are not as versatile & flexible as rsync. To enjoy the features of rsync I’d recommend using it via cygwin or directly via the windows binary of rsync.
If you are one of those who hate linux binaries on windows, you can try using robocopy
Robocopy or robust file copy is a part of windows resource kit since NT4 and now it has been added as standard utility in windows vista, 7 & server flavors.
If you have moved to windows vista or above, then go ahead & fire
Robocopy an be used as extensively as rsync. Like if you want to copy a folder from one location to another, simply go ahead and type
C:> robocopy C:my_dir d:my_dir /s
/s here copies the subdirectories too.
And similar to rsync when we need to transfer the file on remote machines, we can go ahead and use standard windows command method
C:> robocopy my_dir \remote_machinebackup_dir /s /z
/s for recursive copy
/z for maintaining filecopy even beyond network disconnections
If you want to make an exact copy & replicate deletion of file from to be matched at another, try /MIR which stands for mirror.
The main idea about using command line tools for file copy & backups, you can create your own scripts and use backup more efficiently
BTW, some people sent me mails that I don’t cover the commands in depth. Dear readers, the idea is to point you to right tool, its your homework then to explore the features and use it to the best. And yes, if you explored nicely you can even submit your article for this section of the magazine