Backup and "save sd card" scripts (?)

3 posts
by joelkaberg » Tue Nov 06, 2012 2:19 pm
I saw somewhere a script that was supposed to save the sd card by reducing writes done to the card, but cant seem to find it anymore.. anyone with a link?

Also as im running a web server on my PI I thought it'd be good to have backups of the sd card laying around. Best practice I could figure is to take a copy of of the sd card every now and then, I saw something like this
Code: Select all
dd if=/dev/mmcblk0 of=/mnt/sda1/raspberryPi.img

But will this take a copy of the entire sd card? Also is it possible to include a date here, like so
Code: Select all
dd if=/dev/mmcblk0 of=/mnt/sda1/raspberryPi$date.img

that would output an image like so
Code: Select all

(and maybe even delete copys older than 1 month)

This done via a cron job once every week or so

Anyone got anything like this in the works or already done? Please do share if you do :-)
Posts: 14
Joined: Tue Oct 23, 2012 7:02 am
by julianzeidler » Tue Nov 06, 2012 5:10 pm
Hi Joel,

As i am having some Problems with SD-Card corruption I wrote a small script to sync SD card with an image lying on my Samba Server. This has the benefit, that only the changes have to be copied and not whole size of your SD Card. To get the script to run you will need the kpartx and smbfs installed.
The script mounts a Samba share containing your image (if not already mounted), then uses kpartx to make the partitions inside the img accessible and mounts that as well, then it uses rsync to copy changed files from your root filesystem to the img file, before unmounting the filesystems

Code: Select all

#check if nas is allready mounted
mountpoint -q /media/nasdata || mount -t cifs //nas/Volume /media/nasdata/ -o username=XX,pa

#only creat loopback if it does not exist
[ -e /dev/mapper/loop0p2 ] || kpartx -a -v /media/nasdata/2012-09-18-wheezy

#now we try to mount the loopbacks
mountpoint -q /media/virtsolar || mount /dev/mapper/loop0p2 /media/virtsolar
#mountpoint -q /media/virtboot  || mount /dev/mapper/loop0p1 /media/virtboot

#only do rsync if it really is a mountpoint
mountpoint -q /media/virtsolar && rsync -aEAXxq  --delete / /media/virtsolar/ 2> ~/backup_virtsolar_error.txt
#mountpoint -q /media/virtboot  && rsync -xrq  --delete /boot /media/virtboot/  2> ~/backup_virtboot_error.txt

# unmount loop
umount /media/virtsolar
#umount /media/virtboot

#remove loopback devices again
kpartx -d /media/nasdata/2012-09-18-wheezy-raspbian.img

#umount share?
umount /media/nasdata -l

Hope it might be of help.
Posts: 2
Joined: Tue Nov 06, 2012 5:00 pm
by freemanbubu » Wed Nov 07, 2012 5:55 pm

you can use "ramlog" to save your SDCard from 24/24 write

ramlog mount a small part of RAM as virtual disk, and link /var/log to this vdrive.
Every day, it sync your vdrive with /var/log.

look here:
Posts: 111
Joined: Sun Jun 17, 2012 11:12 am