SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-08-18 22:00:09

jmbarnes
#! Junkie
Registered: 2009-05-04
Posts: 250

Remote Backup Script (Over LAN or WAN)

Thought I'd share a little script I've been using to backup to a remote Linux machine. In my case it is to media hooked up to my home-server (or underpowered Home Theater P.C.) Basically it just runs an rsync to it, dropping changes since the previous backup into a dated folder. It does it over ssh (so you'll need to have it installed on whatever you're backing up to.) The one extra nicety is that it checks if you're running the script while on your home network or one a remote network--then acts accordingly. All the variables you'd need to edit for it to work are at the top and should be pretty self explanatory.

You can grab it here: http://crunchbanglinux.org/pastebin/743

Last edited by jmbarnes (2010-08-19 14:31:15)


IRC: PizzaAndWine     Script bits: Incremental Backup | Sleep Timer

Offline

Help fund CrunchBang, donate to the project!

#2 2010-08-19 05:14:05

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,927
Website

Re: Remote Backup Script (Over LAN or WAN)

Hi jmbarnes this is exactly the sort of thing I was going to have to hack together in the next week or two - thank you for saving me some hours of work! smile

I'm a completre beginner with network stuff, so could I bother you with a couple of questions?

1)
I wonder if you could put some concrete examples of paths etc to set at the top of the script, to save people like me from having to look up what the exact syntax is... smile

in particular,
2)
HOMENET="NAME OF HOME NETWORK"
How do I find out the name of my home network? Right now I can ping and get ssh access to another computer on my local network with "remotehostname.local" without knowing my local network name, if there is one.

3)
LOCALADD="ADDRESS OF LOCAL COMPUTER (i.e. 192.168.1.4)"
Does this have to be an IP address? The router might give it a different IP on another occasion. Can't I use "localhostname.local"?

4)
REMOTEADD="ADDRESS OF REMOTE COMPUTER(ie. thisis.mywebsite.com)"
Same question I suppose - "remotehostname.local" would be OK?

5)
I've already found ssh is easy to use (sshfs is handy too), but wondering if the encryption/decryption process doesn't slow things down when transferring lots of data? Since we're talking about a wired connection security shouldn't be a problem should it? I've read that nfs is fast - would there be any point in reading up and learning how to swap ssh for nfs in your script?

6) (...all questions...)
Permissions. I don't see any "sudo"s in there - is this intended only for personal data, not system files like /etc?

Anyway, thanks again for posting this, just when I wanted it smile


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#3 2010-08-19 14:31:04

jmbarnes
#! Junkie
Registered: 2009-05-04
Posts: 250

Re: Remote Backup Script (Over LAN or WAN)

Happy to help to the degree that I can, but I too am a newbie to networking.

1) Paths might look something like this....

INCREMENTS="/media/backup/increments/$BACKUPTIME"
EXCLUDES="/home/USER/bin/backupexcludes.txt"
SOURCEDIR="/home/USER"
DESTDIR="/media/backups/t60stat_home"

Here the increments directory (which is on the destination machine) is created with the variable of $BACKUPTIME so we get a dated directory. Excludes (source machine) is a plain text file of patterns you want to exclude from backing up (a lot of ~/.cache etc here.). Then source is what you'll backup to destination.

2)I should have written ESSID instead of network name. Whatever network network-manager or wicd says you're connected to is the name that goes here. So if you have an unconfigured linksys router it'd be "linksys." Should be easy to change in your router settings.

3) I'd guess that a localhostname might work--though I don't really know. That said if you're going to connect over the internet (not just the local network) then you'll want to be able to forward traffic over specific ports to specified IPs. To me it's always been easier to set up static IPs (or use MAC-address IP-reservation if your router has such a feature) than to deal with things like hostnames.

4) Same answer I suppose. In my case I use the remote backup to backup to my home server when I'm away (office, campus etc.) So here I use myhome.homelinux.org which is the address of my home computer using dynamic dns (dyndns.org). This skips around having to figure out when my home IP address changes.

5) If it is wired at home, NFS is probably a good go. In that case you'll want to set up an NFS server, export the directories, mount the directories, then run an rsync to the mounted directory. I used to do this (NFS while at home, SSHFS on the road) but it wasn't that much quicker than rsync over ssh over the wireless network.

6) I only use it for non-root stuffs. Wouldn't be too hard to slip a few sudos in there. I actually do copy all my root stuff--but its in a .tar archive that my user has access to.


IRC: PizzaAndWine     Script bits: Incremental Backup | Sleep Timer

Offline

#4 2010-08-19 16:44:12

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,927
Website

Re: Remote Backup Script (Over LAN or WAN)

Many thanks for your thoughtful answers smile
That clarifies a lot.

2) network-manager only gives me the ip address of my router, ie 192.168.11.1, and computer's local ip, ie  192.168.11.5. Sometimes the last number is 3 or 4. No name of any kind, linksys or otherwise. Tying a MAC address to a specific IP sounds like a good idea. I'll have to search through the router's (Japanese) interface and see if I can find something.

6) I use sudo (hitherto an rsync backup to a usb stick) because I want to back up other users' data too, as well as some system stuff.

Anyway, thanks again, I'll see what I can do with this as a base.


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo