Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Last active May 9, 2020 05:14
Show Gist options
  • Save benmarwick/ca7cf87d7be63dcd8ea3 to your computer and use it in GitHub Desktop.
Save benmarwick/ca7cf87d7be63dcd8ea3 to your computer and use it in GitHub Desktop.
rsync Windows to Linux, or Windows to a USB external hard drive
  • from Windows to a remote linux server (view as raw to see diagram), I am using Mysys (ie. same as Git bash)
$ cd to_my_dir

                                     source is everything in my_dir
  show progress for large files           |
                |        dir to exclude   |                dir on remote computer to sync up
                |                   |     |                            |
$ rsync -avz   -P ssh --exclude Downloads . too@128.95.155.147:/media/two/LaCie/My\\ Documents
                                                 |           |                     |
                                       remote computer name  |                  need to escape the space with \\
                                                             |
                                               remote computer IP address (https://www.whatismyip.com/)

See here for arguments to rsync: http://linux.die.net/man/1/rsync important ones: -a archive
-v verbose
-r recursive
-t preserve modification times
-z compress
-n dry run
--stats show summary of transfer -h human-readable

  • Copy files from one folder to another folder that already exists, on the same machine:

$ rsync -avz test1/. test2/

$ rsync -avrtz test1/ test2/

  • Here's a windows batch file to make it happen:
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 . 'too@128.95.170.232:/media/two/LaCie/My\ Documents'"
REM rsync complete 
@pause

Using a ssh key

https://bluebill.wordpress.com/2011/05/04/sync-files-from-windows-to-linux-using-ssh/

Here is what I'm doing on windows with a USB external hard drive:

REM Changing directory... (assuming we are in E:/My Documents/My Various Things)
cd ../
REM starting rsync...
bash -c "rsync -avzh -P --chmod=ugo=rwX --stats --timeout=60  --exclude Downloads . '/cygdrive/d/My_Documents'"
REM rsync complete
@pause
REM identify location of fstab with cygpath -w /etc/fstab
REM if you get "permission denied" messages, use CTRL+SHIFT+ENTER cmd to get an administrator command prompt, then run "takeown /f "c:\folder\subfolder" /r" to take ownership of everything in D: -- doesn't make any difference
REM then "ICACLS d:\My_Documents /grant administrators:F"
REM Right-click on My_Documents, Security, Everyone to full control.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment