{"id":329,"date":"2005-09-21T15:40:32","date_gmt":"2005-09-21T22:40:32","guid":{"rendered":"http:\/\/lee.org\/blog\/?p=329"},"modified":"2011-11-09T16:38:42","modified_gmt":"2011-11-10T00:38:42","slug":"using-cygwin-rsync-ssh-and-the-internet-to-backup-my-xp-computer","status":"publish","type":"post","link":"https:\/\/www.lee.org\/blog\/2005\/09\/21\/using-cygwin-rsync-ssh-and-the-internet-to-backup-my-xp-computer\/","title":{"rendered":"Using Cygwin, Rsync, SSH and the internet to backup my XP computer"},"content":{"rendered":"<p><strong>update 11-9-11:<\/strong> consider using <a href=\"http:\/\/www.aboutmyip.com\/AboutMyXApp\/DeltaCopy.jsp\">DeltaCopy<\/a> instead of my home-brewed method below. I haven&#8217;t used it yet, but it looks nice!<\/p>\n<p>I want to back up my Windows XP computer to another Windows XP computer using Rsync and SSH. Since Rsync only runs under *nix, I&#8217;m running it under Cygwin. <\/p>\n<p>There are a couple hurdles to doing this. The one I got stuck on was getting SSH to work without a password. <\/p>\n<p>It&#8217;s so freaking simple to do. You just have to know which instructions do not help accomplish your goal.<\/p>\n<p><!--more--><\/p>\n<p>First, <a href=\"http:\/\/pigtail.net\/LRP\/printsrv\/cygwin-sshd.html\">ignore these instructions from pigtail.net<\/a>. They don&#8217;t work. <a href=\"http:\/\/www.csua.berkeley.edu\/~ranga\/notes\/ssh_nopass.html\">Ignore these instructions from Berkeley.edu<\/a>. They don&#8217;t work. <a href=\"http:\/\/lists.freebsd.org\/pipermail\/freebsd-questions\/2003-March\/000108.html\">Follow these instructions from Freebsd.org<\/a>. They work. Thank you Mike!!<\/p>\n<blockquote><p>\n1) Generate your keys on your local machine:<br \/>\n\t&#8211; ssh-keygen -t rsa<br \/>\n2) When prompted for a password, do not enter one.  This will generate a password-less key called id_rsa, and a public key id_rsa.pub<br \/>\n3) Copy the id_rsa.pub key over to the machine you want to ssh to.  NOTE: change the filename first or you may overwrite your existing RSA key for your remote host.  Like this:<br \/>\n\t&#8211; local: cp id_rsa.pub local.key<br \/>\n\t&#8211; scp local.key remote:<br \/>\n\t&#8211; cat local.key >> .ssh\/authorized_keys<\/p>\n<p>At this point, your remote machine should accept a passwordless login from that &#8220;local&#8221; machine.<\/p>\n<p>Mike<br \/>\nMichael K. Smith         NoaNet\n<\/p><\/blockquote>\n<hr \/>\n<p>Here&#8217;s the rest of it&#8230;.<\/p>\n<p>Let&#8217;s say you want to back up your computer&#8230; The most protected thing you could do would be to make encrypted offsite backups on a regular or even constant basis. But toting around offsite backups are a real bother.<\/p>\n<p>The best (inexpensive and easy to maintain) system I&#8217;ve come up with is thus:<\/p>\n<p>Two WinXP computers over high speed internet. Both computers have Cygwin (installed: ssh, sshd, rsync) and Truecrypt. Every so often, I rsync a backup to the Truecrypted file system. A full 50 gigabyte backup takes about 2 weeks of continuous file transfer (at 50KB\/sec) but subsequent backups take a few hours overnight. It&#8217;s better if the initial backup is done locally but what the hey, it&#8217;s only bandwidth.<\/p>\n<p>I&#8217;ve only recently gotten the system going so I&#8217;ll keep you informed as to how it&#8217;s working for me.<\/p>\n<p>To protect the backup machine, I use <a href=\"http:\/\/www.truecrypt.org\/\">Truecrypt<\/a>. I also use &#8220;Windows Tweakui | My Computer | Drives&#8221; to hide the Truecrypted partition on the backup machine.  The best I could figure for using Truecrypt is to VNC into the backup machine and decrypt the partition before running  a backup process. I&#8217;ve discussed this topic previously in my blog. Go <a href=\"http:\/\/lee.org\/blog\/?s=backup&#038;subButton=Search\">searching<\/a>.<\/p>\n<p><strong>update 9-22-05<\/strong><br \/>\nI had to restart the rsync session several times because the following error would stall things<\/p>\n<blockquote><p>&#8230;Lullaby.mp3<br \/>\nReceived disconnect from [IP removed]: 2: Corrupted MAC on input.<\/p><\/blockquote>\n<p>I googled a little and found some folks on Redhat.com or someplace like that saying how they don&#8217;t have a fix for it but believe it to be a bug in a Linksys router. My Netgear router has the problem as well so phoey. <\/p>\n<p>4.4 gig moved in 20 hours. Yup. It looks like the initial backup will be a 2 week affair. The 75 KB\/sec transfer isn&#8217;t hindering my normal system usage which is a good thing. When I move files over my local network with rsync at about 1.5 MB\/sec, both computers are virtually unusable during the transfer. (<strong>update<\/strong>, there&#8217;s a fix for that. Check the comments)<\/p>\n<p>Stopping and restarting the rsync is solid proof that I&#8217;m on the right track. It takes 30-45 seconds for the computers to sift through the first 4.4 gigabytes for changed files and then resume the transfer.<\/p>\n<p><strong>update 9-23-05<\/strong> I had some trouble trying to install cron (so I could restart failed rsync processes) so I reinstalled Cygwin from scratch. I observe 2 things: 1) Reinstalling this entire pseudo operating system was a SNAP 2)I haven&#8217;t had the failure in several hours even though I didn&#8217;t do anything.<\/p>\n<p><strong>update 9-24-05<\/strong>I installed cron and I run this every hour to restart everything:<\/p>\n<blockquote><p>\n#!\/bin\/bash<\/p>\n<p># kill all of the rsync processes (actually, shoot all the tcsh processes&#8230; they are running rsyncs. Then kill the rsync processes<\/p>\n<p>ps | grep tcsh | awk &#8216;{print $1}&#8217; |  xargs kill  -9<br \/>\nps | grep rsync | awk &#8216;{print $1}&#8217; |  xargs kill  -9<br \/>\nps | grep ssh | awk &#8216;{print $1}&#8217; |  xargs kill  -9<\/p>\n<p># start a backup or two<br \/>\n\/home\/lee\/backup.txt >> \/home\/lee\/backup-log.txt &#038;<br \/>\n#\/home\/lee\/backup2.txt >> \/home\/lee\/backup2-log.txt &#038;\n<\/p><\/blockquote>\n<p>But grrr. After a restart, the file it was working on is restarted from the beginning. That means if it takes more than 1 hour to move an individual file (at my speed, about a 0.25 gig file), my cron job will spin around in circles forever&#8230; &#8230;<\/p>\n<p>Rsync Options to the rescue! &#8220;&#8211;partial-dir=.rsync-partial&#8221; fixes that problem.<\/p>\n<p>Here is the script file I run (I&#8217;ve stripped out some of the boring folders that I backup):<\/p>\n<blockquote><p>\n#!\/bin\/csh<\/p>\n<p>echo &#8220;&#8212;&#8212;&#8212;&#8212; Begin Rsync &#8212;&#8212;&#8212;&#8212; &#8221;<br \/>\necho -n &#8220;start on: &#8221; ; date<\/p>\n<p># notes:<br \/>\n# If you want to push the output to a file, you might do something like this:<br \/>\n#  .\/backup-booty.txt > booty-log.txt 2>&#038;1<br \/>\n#<br \/>\n# This is being run with Cygwin on WinXP on both sides. Several folders initially<br \/>\n#   (for some unknown reason) had default permissions of 000.<br \/>\n#   This caused the first rsync to work and subsequent transfers to crash due to file permission errors.<br \/>\n#   To fix this, I used Cygwin to set file permissions on the client-side to 700.<br \/>\n#<br \/>\n# If the file transfer gets mucked up and the files on the server won&#8217;t delete,<br \/>\n#   run a &#8216;chmod -R 777 *&#8217; on them<br \/>\n#<br \/>\n# It might be useful to run it with the output to a file for analysis later.<br \/>\n# IE:   backup-booty.txt > bootylog.txt<\/p>\n<p>setenv Rsync &#8220;nice +1 rsync&#8221;<br \/>\nsetenv OPTS &#8220;&#8211;verbose &#8211;partial-dir=.rsync-partial &#8211;compress &#8211;recursive &#8211;times &#8211;delete &#8211;rsh=\/usr\/bin\/ssh&#8221;<\/p>\n<p># useful options:<br \/>\n# &#8211;bwlimit=50 limit bandwidth to 50KB\/sec<br \/>\n# &#8211;progress: good for interactive sessions, bad for logged sessions<br \/>\n# &#8211;verbose &#8211;verbose &#8211;verbose: shows exactly what&#8217;s going on. You might want to pipe the output to a file.<br \/>\n# &#8211;compress: good for slow connections, bad for high speed<br \/>\n# &#8211;whole-file: good for fast connections. It won&#8217;t use the rsync algorythm so it won&#8217;t bog down the CPU.<\/p>\n<p># I don&#8217;t run with &#8220;-a&#8221; because it could be good to strip all that permission stuff when restoring the backup<\/p>\n<p>setenv BackupDestination &#8220;Owner@mydomain.com:\/cygdrive\/f\/&#8221;<br \/>\n#setenv BackupDestination &#8220;\/cygdrive\/f\/&#8221;<br \/>\n#setenv BackupDestination &#8220;cg:\/cygdrive\/d\/&#8221;<\/p>\n<p>setenv BackupFolder &#8220;current-backup&#8221;<\/p>\n<p>echo &#8220;rsyncing to: $BackupFolder and $BackupFolderD&#8221;<br \/>\necho &#8220;Options specified: $Rsync, $OPTS&#8221;<\/p>\n<p># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>echo &#8220;Set up backup folder&#8221;<br \/>\ndate<br \/>\n# &#8230; by dropping this very program into the folder. We do this because rsync can&#8217;t create sub-sub-folders blindly<br \/>\n$Rsync $OPTS $0 \\<br \/>\n\t$BackupDestination\/$BackupFolder\/<\/p>\n<p>#echo &#8220;Outlook&#8221;<br \/>\ndate<br \/>\n$Rsync $OPTS \/cygdrive\/c\/Documents\\ and\\ Settings\/Lee\/Local\\ Settings\/Application\\ Data\/Microsoft\/Outlook* \\<br \/>\n\t$BackupDestination$BackupFolder<\/p>\n<p>echo &#8220;My Documents sans My Music and My Videos&#8221;<br \/>\ndate<br \/>\n$Rsync $OPTS &#8211;exclude=&#8221;My Music&#8221; &#8211;exclude=&#8221;My Videos&#8221; \/cygdrive\/c\/Documents\\ and\\ Settings\/Me\/My\\ Documents* \\<br \/>\n\t$BackupDestination$BackupFolder<\/p>\n<p>echo &#8220;Firefox bookmarks&#8221;<br \/>\ndate<br \/>\n$Rsync $OPTS \/cygdrive\/c\/Documents\\ and\\ Settings\/Lee\/Application\\ Data\/Mozilla\/Firefox\/Profiles\/41e9243n.default\/bookmarks.html \\<br \/>\n\t$BackupDestination$BackupFolder\/Firefox-Bookmarks\/ <\/p>\n<p>echo &#8220;Firefox extentions&#8221;<br \/>\ndate<br \/>\n$Rsync $OPTS \/cygdrive\/c\/Documents\\ and\\ Settings\/Lee\/Application\\ Data\/Mozilla\/Firefox\/Profiles\/41e9243n.default\/extensions* \\<br \/>\n\t$BackupDestination$BackupFolder\/Firefox-Extentions\/ <\/p>\n<p>echo &#8220;Start Menu&#8221;<br \/>\ndate<br \/>\n$Rsync $OPTS \/cygdrive\/c\/Documents\\ and\\ Settings\/Lee\/Start\\ Menu* \\<br \/>\n\t$BackupDestination$BackupFolder<\/p>\n<p>echo -n &#8220;&#8212; finished rsync on &#8221; ; date\n<\/p><\/blockquote>\n<p><strong>update 9-25-05 8pm<\/strong> 19 gig moved. I get about 5 GB\/day when it runs continuously&#8230; my estimates were correct :-)<\/p>\n<p><strong>update 9-26-05 9am<\/strong> 22 gig moved. If I run 2 rsync sessions at once, I get 6 GB\/day. The computer lags a bit though. 3 sessions doesn&#8217;t improve performance. It takes about 60 seconds for Rsync to power-up so I changed the cron job to restart the download every 2 hours instead of every hour.  &#8220;* *\/2 * * * \/home\/lee\/restart-backup-cron.txt&#8221;<\/p>\n<p><strong>update 9-29-05<\/strong> 12:26am, enabled &#8211;compression. 33.4 GB on the remote machine. . . . . 8:30pm 9-29-05, 37.9 GB&#8230; thats 5.4 GB per day. A slight improvement over the previous 5GB\/day. I keep most of my files compressed as jpg, mp3, avi, zip, etc&#8230;<\/p>\n<p>I think it might be that the first time a folder is checked, it bogs down the CPU, subsequent checks are 100 times faster and don&#8217;t bog down the machine. <\/p>\n<p><strong>update 10-3-05 12:00am<\/strong> 53.7 GB.. actually, I&#8217;ve been PCAnywhere-ing into the machine and getting that read with Windows Explorer. When I SSH in, &#8216;df&#8217; says 56.6 GB. Bigger numbers are better numbers so there. I set the cron to restart every hour instead of every 2.<\/p>\n<p><strong>update 10-7-05<\/strong>: To make cron run as a service and start automatically when I start my computer (so I can run the cron jobs that start the rsyncs that swallow the flies) I opened a Cygwin shell prompt and typed this<\/p>\n<blockquote><p>cygrunsrv -I cron -p \/usr\/sbin\/cron -a -D<\/p><\/blockquote>\n<p>It makes it an automatically starting Service. :-( (<a href=\"http:\/\/archives.postgresql.org\/pgsql-cygwin\/2001-09\/msg00054.php\">Thanks<\/a>)<\/p>\n<p><strong>10-8-05 update<\/strong> after 15 days and 77 GB, I have a backup in New Jersey. When doing updates, if there are no changes, Rsync verifies this fact in less than 4 minutes. That is astoundingly phenominally wonderfully fast. All hail the Rsync. And good night!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Cygwin, Rsync,  and SSH to backup my computer<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-329","post","type-post","status-publish","format-standard","hentry","category-geekery"],"_links":{"self":[{"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":0,"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lee.org\/blog\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}