Backing up / Imaging PiAware SD card remotely?


#1

Hi guys,

With all the tweaks, updates and options we have with PiAware (mutability, FR24 feeders etc), I’m sure a lot of people will want to try these out, but dont want to risk “hosing” their current PiAware setup.
Being a PC-man, my knowledge of command-line Linux is limited.

So, if I wanted to make a complete image of my current PiAware SD card - that could just be rewritten to the SD if I trash the install - BUT do this over my (wired) network - Pi’s in the attic - what’s the best way of doing this?

THX


#2

Check out http://www.aboutdebian.com/tar-backup.htm for making TAR (compressed) backups of your Pi.

Each Pi runs the following (cron) script twice a week to make a backup and then copy the backup to the server in the closet (I do a local backup then copy to the server so that I get a complete backup even if the server is unavailable). I also run it before I’m about to try something exciting that I may want to back out of… The backup file has the Pi host name and a date stamp. You do give all your Pis different host names, don’t you?

The script assumes you have a (root level) directory /backups – this one also skips mounted servers /sheep and /pigs

(mea culpa, mea culpa, mea maxima culpa – if you have suggestions on how to make this better, I’m open to them!)
(warning: this doesn’t work with “noobs” installs, as they do funky paritioning)


#!/bin/bash
# K6RTM 2014/07/17 back up raspberry pi and copy the backup to server volume /sheep/rpibackups
# using the $HOSTNAME for the backup file
# insure we have a server connection, it's in fstab
sudo mount -a
# put us in the backups directory
cd /backups
# remove old backups (dangerous, I know)
echo "Snuff old backups..."
sudo rm *.gz
# capture our startup time
T="$(date +%s)"
# capture date for date-stamping the backup file
_now=$(date +"%Y-%m-%d")
_bfile="/backups/"$HOSTNAME"backup-$_now.tar.gz"
_sfile="/sheep/rpibackups/"$HOSTNAME"backup-$_now.tar.gz"
# start doing the backup
echo "Starting backup to $_bfile..."
tar -zcpf "$_bfile" --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups --exclude=var/swap --exclude=sheep --exclude=pigs .
# done, let 'em know
T="$(($(date +%s)-T))"
printf "Backed up in %3d minutes.
" "$((T/60))"
# capture time again for copying to server
T="$(date +%s)"
# copy the backup file to the server
echo "Copying $_bfile to $_sfile"
sudo cp "$_bfile" "$_sfile"
T="$(($(date +%s)-T))"
printf "Copied to server in %3d minutes.
" "$((T/60))"


Save this as something like backups.sh in the /backups directory. make sure it’s executable. It excludes a number of system things, as well as the backups directory and specific mounted volumes – otherwise it will try and back up anything and everything you have mounted. This usually takes a long time and fails when the SD card in your Pi fills up…

If you have 5 gigs used on your SD card, this can take up to an hour – be patient. The Pi 2 is faster!

restore is easy–

cd /
sudo tar -zxvpf /backups/

and reboot when it completes.

bob k6rtm


#3

Thanks Bob- looks good!

I only have the Rpi (everything else in te house is PC based, or Android).

Found this, which uses DropBox to copy everything to - which seems ideal (as my RPi already has it’s own wired-network connection.

alexbelezjaks.com/automatic-back … -tutorial/

However, I was originally looking for a way to remotely image the RPi SD card - so I could completely “rebuild it” by a simple re-install of the image if needed.

Looking at the above, I’ll compare this with yours to work out what folders etc to copy.

Will study over the weekend, posted for others’ interest…


#4

Just found this, which looks to create an image over the network (started locally from the Pi, pushed to a network location).

Am looking at pushing this image from my Pi to my PC in the first instance.

cagewebdev.com/index.php/raspber … s-running/

Will have a look at this myself over the weekend.

(Of course, if one of you linux guru’s on here could build that into a cronjob, that would be perfect!).


#5

If you want to do a sd card to sd card image, look for rpi-clone, which does just that – copies your SD card to an SD card attached to a USB port.

https://github.com/billw2/rpi-clone

When I do this, I try and make the system as quiescent as possible, stopping other processes and services.

–bob