You are not logged in.

#1 2011-06-02 17:04:17

ben106
Member
From: Switzerland
Registered: 2009-04-25
Posts: 16

[Solved] Rsnapshot backup of a not-always-on machine

Hello,
I'm setting up a backup system on a small home server (running debian). The server is (almost) always-on, but the machine that has to be backed-up is not (a workstation running archlinux).

For now, it works well (the server backs-up its local files and also the workstation's files via ssh), apart that the workstation has to be on when rsnapshot executes (cron job).

Would there be a solution like "do the daily backup once a day, when the workstation is on" ? By e.g asking the workstation regularly if it is on and if so, backup it, but only max once a day. I saw that anacron does something like this, but as I understood, it is for the case the server is not always on, and not the workstation. Am I right ?

Thanks for the help

Ben

Last edited by ben106 (2011-06-04 11:02:59)

Offline

#2 2011-06-02 21:24:54

owain
Member
Registered: 2009-08-24
Posts: 251

Re: [Solved] Rsnapshot backup of a not-always-on machine

I've got the same setup at home, with a Debian server pulling in backups from my laptop.  I run the following script as an hourly cron job on the server (I know it's a bit hackish and could be tidied up).  Files in $DATEDIR are used for timestamps of the last monthly/weekly/daily backups, and running with an '-f' flag forces a daily backup to be made.

#!/bin/bash

if ! /bin/ping -c 1 192.168.1.33 &> /dev/null; then echo "owain-laptop not available"; exit 1; fi

DATEDIR=/var/lib/rsnap
LASTMONTHLY=$(stat -c %X $DATEDIR/monthly)
LASTWEEKLY=$(stat -c %X $DATEDIR/weekly)
LASTDAILY=$(stat -c %X $DATEDIR/daily)
NOW=$(date +%s)
MONTH=2415600   # 27 days, 23 hours
WEEK=601200   # 6 days, 23 hours
DAY=82800   # 23 hours

SUCCESS=0

if [[ "$(($NOW-$LASTMONTHLY))" -gt "$MONTH" ]]; then
    echo "Starting monthly snapshot"
    rsnapshot -c /etc/rsnapshot.owain-laptop.boot.conf monthly || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.etc.conf monthlyy || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.home.conf monthly || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.var.conf monthly  || SUCCESS="1"
   
    if [[ $SUCCESS == "0" ]]; then
        echo "Monthly snapshot successful"
        touch $DATEDIR/monthly
    else
        echo "Error(s) with monthly snapshot"
    fi
fi

SUCCESS=0

if [[ "$(($NOW-$LASTWEEKLY))" -gt "$WEEK" ]]; then
    echo "Starting weekly snapshot"
    rsnapshot -c /etc/rsnapshot.owain-laptop.boot.conf weekly || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.etc.conf weekly  || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.home.conf weekly || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.var.conf weekly  || SUCCESS="1"
   
    if [[ $SUCCESS == "0" ]]; then
        echo "Weekly snapshot successful"
        touch $DATEDIR/weekly
    else
        echo "Error(s) with weekly snapshot"
    fi
fi

SUCCESS=0

if [[ "$(($NOW-$LASTDAILY))" -gt "$DAY"  || "$1" == "-f" ]]; then
    echo "Starting daily snapshot"
    rsnapshot -c /etc/rsnapshot.owain-laptop.boot.conf daily || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.etc.conf daily  || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.home.conf daily || SUCCESS="1"
    rsnapshot -c /etc/rsnapshot.owain-laptop.var.conf daily  || SUCCESS="1"

    if [[ $SUCCESS == "0" ]]; then
        echo "Daily snapshot successful"
        touch $DATEDIR/daily
    else
        echo "Error(s) with daily snapshot"
    fi
fi

Offline

#3 2011-06-03 09:09:58

ben106
Member
From: Switzerland
Registered: 2009-04-25
Posts: 16

Re: [Solved] Rsnapshot backup of a not-always-on machine

thanks a lot ! I made some minor modifications to your script, will post them as soon as I tested it a little..

Offline

#4 2011-06-04 11:01:30

ben106
Member
From: Switzerland
Registered: 2009-04-25
Posts: 16

Re: [Solved] Rsnapshot backup of a not-always-on machine

Here is the modified script so it better suits my needs :

#!/bin/bash

if ! /bin/ping -c 1 192.168.1.54 &> /dev/null; then echo "enceladus not available"; exit 1; fi

DATEDIR=/home/samba/rsnapshot-enceladus/last_backups

LASTDAILY=$((`stat -c %X $DATEDIR/lastdaily` / 86400)) # number of days since epoch of the last backup
LASTWEEKLY=$((`stat -c %X $DATEDIR/lastdaily` / 86400))
LASTMONTHLY=$((`stat -c %X $DATEDIR/lastdaily` / 86400))
NOW=$((`date +%s` / 86400))

MONTH=30 # number of days between backups
WEEK=7
DAY=1

FAIL=0

if [[ "$(($NOW-$LASTMONTHLY))" -ge "$MONTH" ]]; then
    echo "Starting monthly snapshot"
    rsnapshot -c /etc/rsnapshot-enceladus.conf monthly || FAIL="1" # If rsnapshot failed, set FAIL=1
   
    if [[ $FAIL == "0" ]]; then
        echo "Monthly snapshot successful"
        touch $DATEDIR/lastmonthly
    else
        echo "Error(s) with monthly snapshot"
    fi
fi

FAIL=0

if [[ "$(($NOW-$LASTWEEKLY))" -ge "$WEEK" ]]; then
    echo "Starting weekly snapshot"
    rsnapshot -c /etc/rsnapshot-enceladus.conf weekly || FAIL="1"
   
    if [[ $FAIL == "0" ]]; then
        echo "Weekly snapshot successful"
        touch $DATEDIR/lastweekly
    else
        echo "Error(s) with weekly snapshot"
    fi
fi

FAIL=0

if [[ "$(($NOW-$LASTDAILY))" -ge "$DAY" || "$1" == "-f" ]]; then
    echo "Starting daily snapshot"
    rsnapshot -c /etc/rsnapshot-enceladus.conf daily || FAIL="1"

    if [[ $FAIL == "0" ]]; then
        echo "Daily snapshot successful"
        touch $DATEDIR/lastdaily
    else
        echo "Error(s) with daily snapshot"
    fi
fi

I chose to use days unit instead of seconds, so that a backup is really made every day, not every >23h (personal preference..). That's the most important change, otherwise it is just about IPs and names..
For now, I just could test that the daily backup works, but the weekly and monthly should also work.

Thanks again !

EDIT : The script must be placed in /etc/cron.hourly, and its name must match what "man run-parts" says (e.g foo and not foo.sh)

Last edited by ben106 (2011-06-07 05:43:54)

Offline

#5 2013-05-07 10:21:45

Nareto
Member
From: Pisa,Italy
Registered: 2009-07-18
Posts: 148

Re: [Solved] Rsnapshot backup of a not-always-on machine

the problem with this is that "rsnapshot daily", for example, will simply copy (with hard links) your "hourly.23" to "daily.0". So if your computer was actually turned off for some days (and thus "hourly.23" has the backup of several days ago) you will get an old backup in "daily.0", which is misleading IMHO... this is a problem with rsnapshot though, haven't found any hack for the moment to get around it.

Offline

#6 2013-05-07 13:01:42

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [Solved] Rsnapshot backup of a not-always-on machine

While I feel Nareto has added some useful info. to this thread, it was solved years ago. I am unsure if the OP will see the reply. In accordance to forum policy I close this thread. If further discussion is necessary, please start a new one. Thanks.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

Board footer

Powered by FluxBB