aboutsummaryrefslogtreecommitdiffstats
path: root/dfly-update
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-03-10 20:47:44 +0800
committerAaron LI <aly@aaronly.me>2018-03-10 20:47:44 +0800
commit23461578e97fafd21541730db5dfb7f68f4b4236 (patch)
tree24053df1084fa302ec3e575dec8a7d42a087ac71 /dfly-update
parentd322f373e798c4329c4008086a7e11b28487d643 (diff)
downloaddfly-update-23461578e97fafd21541730db5dfb7f68f4b4236.tar.bz2
Implement the backup command with backup_kernel() and backup_world()
Diffstat (limited to 'dfly-update')
-rwxr-xr-xdfly-update67
1 files changed, 67 insertions, 0 deletions
diff --git a/dfly-update b/dfly-update
index facdbea..9bc9731 100755
--- a/dfly-update
+++ b/dfly-update
@@ -29,6 +29,7 @@ EC_FETCH=14
EC_MOUNT=15
EC_UMOUNT=16
EC_VN=17
+EC_TAR=18
#
@@ -50,6 +51,9 @@ UPDATE_BRANCH=
CACHE_DIR="/var/tmp/${NAME}"
# Directory to mount the system image
MNT_DIR="/mnt/${NAME}"
+# Backup directory
+BACK_DIR="/var/backups/${NAME}"
+
#
# Helper Functions
@@ -303,6 +307,55 @@ umount_image() {
|| exit ${EC_VN}
}
+# Backup the old kernel
+backup_kernel() {
+ [ $# -eq 0 ] || exit ${EC_ARGS}
+ local kerndir="/boot/kernel"
+ local oldkerndir="${kerndir}.old"
+ echo "Backing up current kernel to ${oldkerndir} ..."
+ if [ -d "${oldkerndir}" ]; then
+ warn "Previous backed up kernel already exists!"
+ rm -r ${oldkerndir}
+ warn "Removed previously backed up kernel: ${oldkerndir}"
+ fi
+ mkdir -p ${oldkerndir}
+ chflags noschg ${kerndir}/kernel
+ objcopy --strip-debug ${kerndir}/kernel ${oldkerndir}/kernel
+ for f in ${kerndir}/*.ko; do
+ objcopy --strip-debug ${f} ${oldkerndir}/${f##*/}
+ done
+ [ -f "${kerndir}/initrd.img" ] && \
+ cp -p ${kerndir}/initrd.img ${oldkerndir}
+ [ -f "${kerndir}/initrd.img.gz" ] && \
+ cp -p ${kerndir}/initrd.img.gz ${oldkerndir}
+ echo "Backed up old kernel at: ${oldkerndir}"
+}
+
+# Backup the old world
+#
+# backup_world(backfile)
+#
+backup_world() {
+ [ $# -eq 1 ] || exit ${EC_ARGS}
+ local backfile="$1"
+ local backdir=$(dirname "${backfile}")
+ echo "Backing up current world to ${backfile} ..."
+ [ ! -d "${backdir}" ] && mkdir -v ${backdir}
+ if [ -f "${backfile}" ]; then
+ warn " => Previously backed up world exists!"
+ rm -f "${backfile}"
+ warn " => Removed previously backed world: ${backfile}"
+ fi
+ tar -czf "${backfile}" \
+ --options gzip:compression-level=1 \
+ -C / \
+ etc \
+ bin sbin lib libexec \
+ usr/bin usr/sbin usr/lib usr/libexec \
+ && echo " => DONE" \
+ || exit ${EC_TAR}
+}
+
}
@@ -335,6 +388,8 @@ Usage:
Download the given image and check aginst the given MD5
mount <filepath>
Mount the given image file
+ backup
+ Back up the current kernel and world
_EOF_
echo
cmd_version
@@ -412,6 +467,14 @@ cmd_mount() {
mount_image "${filepath}" "${MNT_DIR}"
}
+# Back up the current kernel and world
+cmd_backup() {
+ [ $# -eq 0 ] || exit ${EC_ARGS}
+ backup_kernel
+ backfile="${BACK_DIR}/world.tar.gz"
+ backup_world "${backfile}"
+}
+
#
# Main
@@ -438,6 +501,10 @@ case "${COMMAND}" in
shift
cmd_mount "$@"
;;
+ backup)
+ shift
+ cmd_backup
+ ;;
help|--help|-h|*)
cmd_usage
;;