I recenting installed attic backup on my debian 6 server. You can see how I did that here.. Below is docs on how I got it up and running the way I wanted.

I'm going to use the newish attic backup on my webserver. I will do a full system backup with it to NFS.

Note: I'm running all these commands as root

Before running the script:

Before running the above script follow this and initialize your attic:

attic init /root/folder-created-previously/atticname.attic

If you want to use encryption, initialize the attic like:

attic init --encryption=keyfile /root/folder-created-previously/atticname.attic

This will create a keyfile located int ~/.attic/key/ . Make a backup of this file someplace else (cough keepass).

The script:

Lets prep a folder to store all our scripts in our root home folder and create the script file:

mkdir ~/scripts
nano ~/scripts/atticbackup.sh

This is what my script looks like:

#!/bin/sh
REPOSITORY=/root/folder-previouly-created/atticname.attic  #no backslash at the end of this
NFSMOUNT=/root/folder-previouly-created  #no backslash at the end of this
NFSDIR="nfsurl.OR.ip.com:/somefolder/on/nfs"

LOGFILE=/var/log/atticbackup

# you may beable to comment this out, but in debian squeeze, i had to compile openssl to a newer version
#   and needed to specify the newer libcrypto path
#   https://github.com/jborg/attic/pull/23
# also set path to attic since crontab hates on me sometimes.
export PATH=$PATH:/usr/local/bin
export ATTIC_LIBCRYPTO_PATH=/usr/lib/libcrypto.so.1.0.0

###############start of script#################   
exec >> $LOGFILE 2>&1

#simple function that just prints the time and the info you pass to it
echotime () {
  echo "---------- `date +%Y-%m-%d--%H:%M:%S` ----$1------------"
}

# simple function to check if nfs is mounted
checkmount () {
  #http://stackoverflow.com/a/14698865
  #http://stackoverflow.com/a/9422947
  if mount | grep $NFSMOUNT > /dev/null; then
      return 1
  else
      return 0
  fi
}

echotime "Script Start"

# mount nfs if not mounted
# if your not using NFS, you can delete this section all together
if checkmount; then
  echotime "NFS not mounted, attepting to mount"
  mount -v $NFSDIR $NFSMOUNT -o nolock
  #check again if its mounted
  if checkmount; then
     echotime "ERROR: NFS not mounted, exiting \n"
     exit 1
  fi
fi

# Backup all of / except a few excluded directories
# if your running into issues, add -v after create for verbose mode
# the below / means backup all of root.
echotime "ATTIC CREATE"
attic create --stats                            \
    $REPOSITORY::host.stscode-`date +%Y-%m-%d--%H:%M:%S`  \
    /                                           \
    --exclude /sys                              \
    --exclude /mnt                              \
    --exclude /dev                              \
    --exclude /media                            \
    --exclude /lost+found                       \
    --exclude /proc                             \
    --exclude /run

# Use the `prune` subcommand to maintain 7 daily, 4 weekly
# and 6 monthly archives.
echotime "ATTIC PRUNE"
attic prune -v $REPOSITORY --keep-hourly=23 --keep-daily=7 --keep-weekly=4 --keep-monthly=6

#unmount the NFS folder, I do this b/c
#   if it stays mounted, sometimes servers freak
#   out when rebooting.
# Uncomment the below 2 lines if you need to unmount every time.
#echotime "UNMOUNT"
#umount -v $NFSMOUNT

# end of script
echotime "End of Script"

Make your script script executable chmod +x /root/scripts/atticbackup.sh
run the script bash /root/scripts/atticbackup.sh

You can see what is happening by runing tail -f on your log file:

tail -f /var/log/atticbackup

If your running into issues, edit the script and add a -v to the attic create --stats line like so: attic create -v --stats

Run it hourly with Crontab:

  • Add it to your crontab to run every hour: crontab -e
  • And add this: 0 * * * * bash /root/scripts/atticbackup.sh