I have MinGW (also known as 'Git Bash') on Windows 7, and a batch file that runs rsync to back up files on an external drive on a remote linux computer. Here's the batch file (my_rsync_file.bat
)
REM Changing directory... (assuming we are in G:/My Documents/My Various Things)
cd ../
REM starting rsync...
bash -c "rsync -avzh -P --stats --timeout=60 --exclude Downloads . '[email protected]:/media/my_remote_linux_computer/LaCie/My\ Documents'"
Here's a bit of line-by-line explanation:
REM Changing directory... (assuming we are in G:/My Documents/My Various Things)
This just emits a message to remind me what's going on.
cd ../
This changes directory one level up from where the batch file is (to 'My Documents'). The batch file is in an external drive on my Windows computer. I want to sync all of the 'My Documents' folder on this external drive with a folder of the same name on an external drive on my remote linux computer.
REM starting rsync...
Just prints another message.
bash -c "rsync -avz -P --stats --timeout=60 --exclude Downloads . [email protected]:/media/my_remote_linux_computer/LaCie/My\\ Documents"
bash
: starts MinGW which has a built-in rsync library
-c
: not sure what this does
rsync
: library to sync files, comes with MinGW
-avzh
: a-Archive, v-Verbose, z-Compress, h-Human-readable, these are the common options (more: http://linux.die.net/man/1/rsync)
-P
: show progress for big files so I know if it's frozen or not
--stats
: show summary of how many files and bytes transferred at the end
--timeout=60
: kill it after 60 seconds if it gets stuck
--exclude
omit files/directories from sync, in this case I exclude a directory called 'Downloads'
.
: indicates to sync all the contents of 'My Documents' (expect the specified thing to exclude in the line above)
my_remote_linux_computer
: name of my remote linux computer (not it's actual name ;)
@128.95.155.200
: the IP addres of my remote linux computer, from https://www.whatismyip.com/ (not my actual IP address :)
/media/my_remote_linux_computer/LaCie/My\\ Documents
: the path to the directory on my remote linux computer that I want to receive the files. It's an external drive.
Note that the space in "My Documents" is escaped with two backslashes, and the full name and directory of the remote destination is surrounded by double quote marks.
When I start double-click on the bat file I'm prompted for the password for my remote linux computer. When it completes I get some summary output and am prompted to press any key to close.