From 2e7a758726420a9107a786968b4f577e5a461d87 Mon Sep 17 00:00:00 2001 From: crowzero Date: Thu, 18 Jun 2015 23:33:19 +0200 Subject: [PATCH 1/5] quiet modus to schedule the script as a cron scrip Version 1.3 2015/06/18 add -q (quiet) option for use as cron script -q only works with existing backups. It won't initialize the destination SD card partitions with dd! Please initialize the destination SD card from the shell (by hand) for the first time. This is to protect you for accidentally overwriting a SD Card. --- rpi-clone | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/rpi-clone b/rpi-clone index 6b28835..1a0353f 100755 --- a/rpi-clone +++ b/rpi-clone @@ -1,6 +1,13 @@ #!/bin/bash -VERSION=1.2 +VERSION=1.3 +# Version 1.3 2015/06/18 +# * add -q (quiet) option for use as cron script +# -q only works with existing backups, +# it won't initialize the destination SD card partitions with dd! +# Please initialize the destination SD card from the shell (by hand) +# for the first time. +# This is to protect you for accidentally overwriting a SD Card. # Version 1.2 2015/02/17 # * add -x option # * tweak some echo messages @@ -59,11 +66,12 @@ fi usage() { echo "" - echo "usage: $PGM sdN {-f|--force-initialize} {-v|--verbose} {-x}" + echo "usage: $PGM sdN {-f|--force-initialize} {-v|--verbose} {-x} {-q|--quite}" echo " Example: $PGM sda" echo " -v - list all files as they are copied." echo " -f - force initialize the destination partitions" echo " -x - use set -x for very verbose bash shell script debugging" + echo " -q - use quiet modus to schedule the script as a cron script" echo "" echo " Clone (rsync) a running Raspberry Pi file system to a destination" echo " SD card 'sdN' plugged into a Pi USB port (via a USB card reader)." @@ -96,6 +104,7 @@ usage() } VERBOSE=off +QUITE_FOR_CRON=false while [ "$1" ] do @@ -113,6 +122,9 @@ do -h|--help) usage ;; + -q|--quite) + QUITE_FOR_CRON=true + ;; *) if [ "$DST_DISK" != "" ] then @@ -143,6 +155,12 @@ fi unmount_or_abort() { + if [ "$QUITE_FOR_CRON" = "true" ] + then + echo "Sorry, mounted devices in quite_cron mode is not allowed." + echo -e "Aborting!\n" + exit 0 + fi echo -n "Do you want to unmount $1? (yes/no): " read resp if [ "$resp" = "y" ] || [ "$resp" = "yes" ] @@ -246,6 +264,12 @@ if [ "$DST_BOOT_PARTITION_TYPE" != "$SRC_BOOT_PARTITION_TYPE" ] || \ [ "$DST_ROOT_PARTITION_TYPE" != "$SRC_ROOT_PARTITION_TYPE" ] || \ [ "$FORCE_INITIALIZE" = "true" ] then + if [ "$QUITE_FOR_CRON" = "true" ] + then + echo "Sorry, now new disk setup allowed in quite_cron mode." + echo -e "Aborting!\n" + exit 0 + fi CLONE_MODE="rsync all files to $DST_DISK root file system" echo "" if [ "$FORCE_INITIALIZE" = "true" ] @@ -352,8 +376,14 @@ echo "===============================" # If this is an SD card initialization, can watch progress of the clone # in another terminal with: watch df -h # -echo -n "Final check, is it Ok to proceed with the clone (yes/no)?: " -read resp + +if [ "$QUITE_FOR_CRON" != "true" ] +then + echo -n "Final check, is it Ok to proceed with the clone (yes/no)?: " + read resp +else + resp="y" +fi if [ "$resp" != "y" ] && [ "$resp" != "yes" ] then echo -e "Aborting the disk clone.\n" @@ -476,9 +506,11 @@ echo "" # Eg. modify $CLONE/etc/hostname, $CLONE/etc/network/interfaces, etc # if I'm cloning into a card to be installed on another Pi. # -echo -n "Hit Enter when ready to unmount the /dev/$DST_DISK partitions..." -read resp - +if [ "$QUITE_FOR_CRON" != "true" ] +then + echo -n "Hit Enter when ready to unmount the /dev/$DST_DISK partitions..." + read resp +fi echo "unmounting $CLONE/boot" umount $CLONE/boot -- 2.39.5 From 12064bc045726177968bd5de4048938c935dcf70 Mon Sep 17 00:00:00 2001 From: Minh Quan HO Date: Sun, 26 Jul 2015 21:47:12 +0200 Subject: [PATCH 2/5] add dry-run mode in RSYNC_OPTIONS --- rpi-clone | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rpi-clone b/rpi-clone index 6b28835..08c6049 100755 --- a/rpi-clone +++ b/rpi-clone @@ -62,6 +62,7 @@ usage() echo "usage: $PGM sdN {-f|--force-initialize} {-v|--verbose} {-x}" echo " Example: $PGM sda" echo " -v - list all files as they are copied." + echo " -n - do a dry-run of rsync." echo " -f - force initialize the destination partitions" echo " -x - use set -x for very verbose bash shell script debugging" echo "" @@ -104,6 +105,9 @@ do VERBOSE=on RSYNC_OPTIONS=${RSYNC_OPTIONS}v ;; + -n|--dry-run) + RSYNC_OPTIONS=${RSYNC_OPTIONS}n + ;; -f|--force-initialize) FORCE_INITIALIZE=true ;; -- 2.39.5 From 33e20e62ed90e26c01b8c53ad5db81c863731ab6 Mon Sep 17 00:00:00 2001 From: Minh Quan HO Date: Sun, 16 Aug 2015 18:22:50 +0200 Subject: [PATCH 3/5] Add dry-run mode (-n) and disk-searching by UUID mode (-u) --- rpi-clone | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rpi-clone b/rpi-clone index 7960cb1..ae9ece3 100755 --- a/rpi-clone +++ b/rpi-clone @@ -1,6 +1,11 @@ #!/bin/bash -VERSION=1.3 +VERSION=1.4 +# Version 1.4 2015/08/16 +# * add -n (--dry-run) option for rsync +# * add -u (--uuid) option to auto-detect disk by UUID. +# System on reboot may change its disk symbol mapping, thus dangerous. +# It is more secure searching by UUID. # Version 1.3 2015/06/18 # * add -q (quiet) option for use as cron script # -q only works with existing backups, @@ -70,6 +75,7 @@ usage() echo " Example: $PGM sda" echo " -v - list all files as they are copied." echo " -n - do a dry-run of rsync." + echo " -u - UUID of one of a disk partition, used when disk is not passed." echo " -f - force initialize the destination partitions" echo " -x - use set -x for very verbose bash shell script debugging" echo " -q - use quiet modus to schedule the script as a cron script" @@ -117,6 +123,10 @@ do -n|--dry-run) RSYNC_OPTIONS=${RSYNC_OPTIONS}n ;; + -u|--uuid) + shift + DST_DISK=$(blkid -U $1 | tail -c 5 | head -c 3) + ;; -f|--force-initialize) FORCE_INITIALIZE=true ;; -- 2.39.5 From 83331c148a93c2e4f17ce97688baff1ac1765b18 Mon Sep 17 00:00:00 2001 From: Minh Quan HO Date: Mon, 9 Nov 2015 17:52:54 +0100 Subject: [PATCH 4/5] add path to tail and head --- rpi-clone | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rpi-clone b/rpi-clone index ae9ece3..f545cb6 100755 --- a/rpi-clone +++ b/rpi-clone @@ -28,6 +28,9 @@ VERSION=1.4 PGM=`basename $0` RSYNC_OPTIONS="--force -rltWDEgopt" +BLKID="/sbin/blkid" +TAIL="/usr/bin/tail" +HEAD="/usr/bin/head" # List of extra dirs to create under /mnt. OPTIONAL_MNT_DIRS="clone mnt sda sdb rpi0 rpi1" @@ -125,7 +128,7 @@ do ;; -u|--uuid) shift - DST_DISK=$(blkid -U $1 | tail -c 5 | head -c 3) + DST_DISK=$($BLKID -U $1 | $TAIL -c 5 | $HEAD -c 3) ;; -f|--force-initialize) FORCE_INITIALIZE=true -- 2.39.5 From 16b6da29e48551b0bdde476552e2d77712363d00 Mon Sep 17 00:00:00 2001 From: Minh Quan HO Date: Sat, 11 Jun 2016 11:22:57 +0200 Subject: [PATCH 5/5] add type disk --- rpi-clone | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rpi-clone b/rpi-clone index f545cb6..3cae887 100755 --- a/rpi-clone +++ b/rpi-clone @@ -416,7 +416,7 @@ fi # Mount destination filesystems. echo "=> Mounting $DST_ROOT_PARTITION ($DST_ROOT_VOL_NAME) on $CLONE" -if ! mount $DST_ROOT_PARTITION $CLONE +if ! mount -t ext4 $DST_ROOT_PARTITION $CLONE then echo -e "Mount failure of $DST_ROOT_PARTITION, aborting!\n" exit 0 @@ -428,9 +428,9 @@ then fi echo "=> Mounting $DST_BOOT_PARTITION on $CLONE/boot" -if ! mount $DST_BOOT_PARTITION $CLONE/boot +if ! mount -t vfat $DST_BOOT_PARTITION $CLONE/boot then - umount $CLONE + umount -t ext4 $CLONE echo -e "Mount failure of $DST_BOOT_PARTITION, aborting!\n" exit 0 fi @@ -529,10 +529,10 @@ then read resp fi echo "unmounting $CLONE/boot" -umount $CLONE/boot +umount -t vfat $CLONE/boot echo "unmounting $CLONE" -umount $CLONE +umount -t ext4 $CLONE echo "===============================" -- 2.39.5