Skip to content

Instantly share code, notes, and snippets.

@bonelifer
Forked from giggio/backupPartition
Created February 19, 2016 05:04
Show Gist options
  • Save bonelifer/fc2dbc29da24f49d0c2b to your computer and use it in GitHub Desktop.
Save bonelifer/fc2dbc29da24f49d0c2b to your computer and use it in GitHub Desktop.
Backup sd card partitions
#!/bin/bash
echo deleting local files older than a week...
find /media/data/backup/* -mtime +7 -type f -delete
echo backuping up /dev/mmcblk0p1...
if [ ! -f /media/data/backup/$(date +%Y%m%d)_mmcblk0p1.img ]; then
dd if=/dev/mmcblk0p1 of=/media/data/backup/$(date +%Y%m%d)_mmcblk0p1.img
fi
echo backuping up /dev/mmcblk0p2...
if [ ! -f /media/data/backup/$(date +%Y%m%d)_mmcblk0p2.img ]; then
dd if=/dev/mmcblk0p2 of=/media/data/backup/$(date +%Y%m%d)_mmcblk0p2.img
fi
echo deleting remote files older than a month...
find /mnt/public/Backup/osmc/201*.img -mtime +10 -type f -delete
echo copying mmcblk0p1.img to network...
if [ -f /media/data/backup/$(date +%Y%m%d)_mmcblk0p1.img ]; then
cp /media/data/backup/$(date +%Y%m%d)_mmcblk0p1.img /mnt/public/Backup/osmc/
fi
echo copying mmcblk0p2.img to network...
if [ -f /media/data/backup/$(date +%Y%m%d)_mmcblk0p2.img ]; then
cp /media/data/backup/$(date +%Y%m%d)_mmcblk0p2.img /mnt/public/Backup/osmc/
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment