-
Notifications
You must be signed in to change notification settings - Fork 1
/
raspberrypi-dd-backup.sh
executable file
·84 lines (73 loc) · 1.75 KB
/
raspberrypi-dd-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Introduction
# This is a simple script to create an image backup from Raspberry Pi SD card and probably other sd cards as well.
#
# Author: Tronde (trondeATmy-it-brainDOTde)
# Source:
#
# * [https://www.raspberrypi.org/documentation/linux/filesystem/backup.md](https://www.raspberrypi.org/documentation/linux/filesystem/backup.md)
#
# Licence: [GPLv3](https://github.com/Tronde/raspberrypi-dd-backup/blob/main/LICENSE)
#
## How to use
#
# 1. Copy CONFIG.sample to config
# 2. Edit config and specify `SRC`, `DEST` and wether or not you like to use compression
# 3. Optional: Setup cronjob to run `raspberrypi-dd-backup.sh` as `root` to schedule your backup job
# Enable debugging
# set -x
# VARIABLES
SCRIPTNAME=`basename ${0}`
PROGDIR=$(dirname $(readlink -f ${0}))
. ${PROGDIR}/CONFIG
# FUNCTIONS
usage()
{
cat << EOF
usage: $0 OPTIONS
This script backups your SD card to an image file.
Parameters -S and -T are optional and overwrites values from CONFIG file.
OPTIONS:
-h Shows this text
-S Specifies the path of the SD card
-T Specifies the the target image file
EOF
}
do_dd_backup()
{
dd bs=4M if=${SRC} of=${DEST}
}
do_dd_backup_w_compression()
{
dd bs=4M if=${SRC} | gzip > ${DEST}.gz
}
# Main
while getopts .hS:T:. OPTION
do
case $OPTION in
h)
usage
exit;;
S)
SRC="${OPTARG}"
;;
T)
DEST="${OPTARG}"
;;
?)
usage
exit;;
esac
done
## Some checks
if [[ ! $(which dd) ]]; then
echo "dd was not found on this system."
fi
if [[ -z $SRC || -z $DEST ]]; then
echo "Please specify SRC and/or DEST in CONFIG or via Options -S and -T."
fi
if [[ ! -z $SRC || ! -z $DEST ]] && [[ "$ZIP" == true || "$ZIP" == TRUE ]]; then
do_dd_backup_w_compression
else
do_dd_backup
fi