Created
June 18, 2014 11:02
-
-
Save alepez/55af911c7dfd3d2e18d5 to your computer and use it in GitHub Desktop.
backup/resume sd with three partitions (boot, system, contents). Made for Rapsberry Pi
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 | |
ACTION=$1 | |
SRC=$2 | |
DST=$3 | |
function pull { | |
mkdir "${DST}" | |
cd "${DST}" | |
mkdir mnt mnt/1 mnt/2 mnt/3 | |
mount -o ro "${SRC}1" mnt/1 | |
mount -o ro "${SRC}2" mnt/2 | |
mount -o ro "${SRC}3" mnt/3 | |
( cd mnt/1 && tar cpvf ../../1.tar . ) | |
( cd mnt/2 && tar cpvf ../../2.tar . ) | |
( cd mnt/3 && tar cpvf ../../3.tar . ) | |
umount mnt/1 | |
umount mnt/2 | |
umount mnt/3 | |
rmdir mnt/1 mnt/2 mnt/3 mnt | |
} | |
function fdisk_batch { | |
cat <<EOF | |
n | |
p | |
1 | |
+32M | |
t | |
b | |
n | |
p | |
2 | |
+4G | |
n | |
p | |
3 | |
w | |
EOF | |
} | |
function push { | |
dd if=/dev/zero of="${DST}" bs=512 count=1 | |
fdisk_batch | fdisk "${DST}" | |
sleep 1 | |
cd "${SRC}" | |
mkdir mnt mnt/1 mnt/2 mnt/3 | |
mkfs.vfat -n BOOT "${DST}1" | |
mkfs.ext4 -L LINUX "${DST}2" | |
mkfs.ext4 -L MOD "${DST}3" | |
sleep 1 | |
mount "${DST}1" mnt/1 | |
mount "${DST}2" mnt/2 | |
mount "${DST}3" mnt/3 | |
( cd mnt/1 && tar xpvf ../../1.tar ) | |
( cd mnt/2 && tar xpvf ../../2.tar ) | |
( cd mnt/3 && tar xpvf ../../3.tar ) | |
echo | |
echo | |
read -p "hostname: " hostname | |
echo ${hostname} > mnt/2/etc/hostname | |
umount mnt/1 | |
umount mnt/2 | |
umount mnt/3 | |
rmdir mnt/1 mnt/2 mnt/3 mnt | |
} | |
case $ACTION in | |
pull) pull | |
;; | |
push) push | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment