dolorosus / RaspiBackup

Backup your raspi
GNU General Public License v3.0
13 stars 4 forks source link
backup backupfile raspberry raspberry-pi rsync rsync-backup

RaspiBackup.sh

Script to backup a Raspberry Pi SDCARD to an imagefile. The resulting file can be installed to a sdcard. Refer to https://www.raspberrypi.org/documentation/installation/installing-images/README.md

Read this text to the end, before use!

This script creates system backup to an image file. It creates backups of the device where the system was booted. It does not matter if the system was started from an SD card or a SSD drive. The size of the image will be calculated as the used size of the / partition plus 550m for /boot plus 1000mb reserve. This is not the size of the entire device, as 30 GB for a SSD drive where only 4 GB of root partition resides.

It is really helpful, if you run your system from a large partition residing on a SSD drive.

:stop_sign: Using an imager all existing data on the target will be removed.

:bulb: If your destination contains other partitions you want to keep, do the following:

Usage

E.g.:

Examples:

Start backup to backup.img, the -c option creates the file if it does not exist. If it does exist, it is deleted and recreated. The size of the image corresponds to the used size of the root partition, plus additional 500Mb for /boot and 1000Mb reserve.

RaspiBackup.sh start -c /path/to/backup.img

Start backup to backup.img, creating it if it does not exist, limiting the size to 8000M. Keep in mind: you are responsible defineing a size large enough to hold all files to backup! There's no such thing as a size check.

RaspiBackup.sh start -s 8000 -c /path/to/backup.img

Refresh of backup.img.

RaspiBackup.sh start /path/to/backup.img

Mount the RPi's Image in /mnt/backup.img:

RaspiBackup.sh mount /path/to/backup.img /mnt/backup.img

Unmount the Image from default mountdir (/mnt/backup.img/):

RaspiBackup.sh umount /path/to/backup.img

show allocation of Image:

RaspiBackup.sh showdf /path/to/backup.img

increase the size of the Image by 1000M:

RaspiBackup.sh resize  /path/to/backup.img

increase the size of the Image by a specific amount (here 2000M):

RaspiBackup.sh resize -s 2000  /path/to/backup.img

:zap: Caveat:

This script takes a backup while the source partitions are mounted and in use. The resulting imagefile will be inconsistent!

To reduce inconsistencies, you need to terminate as many services as possible before you start backing up. You can put the system in rescue mode (be careful: new SSH connections are not possible in rescue mode), take the backup and put your system back in default mode.
A sample is given as WeeklyBackup.sh. WeeklyBackup.sh.

Recommendation:

Use a filesystem for the target that can handle snapshots (e.g. BTRFS). Creating a snapshot, before starting a backup, results in a space efficient versioning backup.