2

I'm wanting to do an incremental backup from my Linux computer to server. I've made the ssh link and I can at least get RSYNC to load the files incrementally, which I plan to do daily using cron.daily, but I want the server (Synology 213j) to take care of tarring the file, though - in my mind - I think it would be fine for my computer to tell the server to TAR the file every week and then put it in weekly, then tar it every month, and finally every two months.

The code I found that sounded somewhat like it might work is this example.

ssh root@192.168.1.105 "tar cvpfz - / --exclude="tmpl" | ssh regx@192.168.1.102 "cat > /media/shared/backup/iphone/iphone_bak_$today.tgz"

However, this looks like it's piping an iPhone to a server backup and it's probably much more complicated than I'll actually need.

Bonus question: would I be better off trying to run the TAR code on the server itself?

  • I saw that post, but I don't think that's quite what I'm going for. – lupaanst Apr 16 '14 at 02:19
  • 1
    This command isn't what you want? tar -cf - /path/to/backup/dir | ssh remotehost "cat - > backupfile.tar"? That's right from the accepted A and would seem to do what you want. You'll have to modify it but that's a parred down version of what you have above. Also can you elaborate on "incremental backup"? That's a loaded phrase the way you've used it. Do you mean incremental as in daily vs. incremental as in only the files that have changed from some prior backup? – slm Apr 16 '14 at 02:21
  • Well, I'm using a laptop and I'd rather use rsync, since I'm occasionally on a spotty network. If I'm reading that code correctly, it tars the files and transfers it to the server via ssh, right? – lupaanst Apr 16 '14 at 02:23
  • As the file is being tarred it's being streamed out over STDOUT through an ssh connection where the contents are then written to disk on the remote server side. – slm Apr 16 '14 at 02:24
  • rsync does nothing to compress the results, it simply makes duplicates from one location to another. True it will only sync what's changed but your Q is very unclear which direction you're trying to shoot for. – slm Apr 16 '14 at 02:26
  • Ooh. That could actually work. Would it have any sort of checksum to verify that it's in the correct format on the other side? – lupaanst Apr 16 '14 at 02:28
  • I'm unclear what you're trying for. It sounds like you want to set up rsync on your laptop, then after rsync finishes, run tar on the server? In which case, isn't that just rsync … && ssh user@server 'tar …' ? But have you considered backup software? – derobert Apr 16 '14 at 02:30
  • Yes there are 2 forms for using rsync. The default behavior looks at timestamp and filesize to compare. The latter and more time consuming check performs a full checksum to compare files. – slm Apr 16 '14 at 02:34
  • Here's another example from this site of how you could do what you want using rsync: Automatic scheduled backup of website (/var/www and MySQL dump) – slm Apr 16 '14 at 02:38
  • Okay, let's clear this up.

    Laptop Backup: cron.daily executes script daily.sh that will copy the files bit for bit to my remote server, which is set up with a Daily folder. I'm backing up /var/ /etc/ and /home/.

    I'm thinking about having it sync the changes in a different folder every day after that, in case I delete something accidentally.

    Where I got hazy, was whether or not I needed to set up a cron.weekly to tell the server to tar the remote daily files I've been making all week (and delete them) or if I should set a serverside crontab for that, and how to best execute it.

    – lupaanst Apr 16 '14 at 02:41

1 Answers1

1

There's a great tutorial on doing incremental backups called "Easy Automated Snapshot-Style Backups with Linux and Rsync". It's somewhat dated but sounds like it might be good reading for what you're trying to do. Here's a link: http://www.mikerubel.org/computers/rsync_snapshots/

Based on the above tutorial, a utility called rsnapshot has also been created: http://www.rsnapshot.org/

  • +1 Indeed, there are tools already written and debugged, and they should be preferred over quick hacks. – derobert Apr 16 '14 at 02:48
  • I do like this a lot, especially his rotating script. Now what about the tar issue. Should the server tar the file instead of the computer telling the server to tar it? – lupaanst Apr 16 '14 at 02:55