Created
June 25, 2021 19:53
-
-
Save nycki93/c62f16188d47ce7621bb1c9703b64b20 to your computer and use it in GitHub Desktop.
my backup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| _run () | |
| { | |
| echo $@ | |
| if [ "$DRY_RUN" == false ]; then | |
| $@ | |
| fi | |
| } | |
| BACKUP="/mnt/backup" | |
| DATA="/mnt/data" | |
| TODAY=$(date -u +"%Y-%m-%dT%H-%M-%SZ") | |
| NEW_DATA="data_$TODAY" | |
| NEW_OS="os_$TODAY.img" | |
| OLD_DATA=$(ls $BACKUP | grep ^data | tail -1) | |
| OLD_OS=$(ls $BACKUP | grep ^os | tail -1) | |
| echo "Found data snapshot $OLD_DATA" | |
| echo "Saving data snapshot $NEW_DATA" | |
| _run rsync -a --link-dest \ | |
| $BACKUP/$OLD_DATA \ | |
| $DATA \ | |
| $BACKUP/$NEW_DATA | |
| echo "*** Saving system image to $NEW_OS ***" | |
| _run dd if=/dev/mmcblk0 of=$BACKUP/$NEW_OS bs=16M status=progress | |
| echo "*** Shrinking raspberry pi image ***" | |
| _run pishrink -z $BACKUP/$NEW_OS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment