From cd4a366d24657fe23cfbf4ccd88138da4928c160 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Wed, 19 Mar 2025 13:36:57 +0700 Subject: [PATCH] added backup disk and backup folder directory --- backup | 43 +++++++++++++++++++++++++++++++++++++++++++ backup_folder | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100755 backup create mode 100755 backup_folder diff --git a/backup b/backup new file mode 100755 index 0000000..69e4e91 --- /dev/null +++ b/backup @@ -0,0 +1,43 @@ +#!/bin/sh + +if [ "$(id -u)" != "0" ]; then + echo "You must be root" + exit 1 +fi + +create_backup() { + disk=$1 + archive=$2 + dd if=$disk status=progress | gzip -9 > $archive +} + +restore_backup() { + archive=$1 + disk=$2 + gzip -dc $archive | dd of=$disk status=progress +} + +print_help() { + printf "usage:\n\t$0 (create|restore)\nexample:\n\t$0 create (disk) (archive)\n\t$0 restore (archive) (disk)\n" +} + +case "$1" in + "create") + if [[ "$2" == "" || "$3" == "" ]]; then + print_help + exit 1 + fi + create_backup $2 $3 + ;; + "restore") + if [[ "$2" == "" || "$3" == "" ]]; then + print_help + exit 1 + fi + restore_backup $2 $3 + ;; + *) + print_help + ;; +esac + diff --git a/backup_folder b/backup_folder new file mode 100755 index 0000000..f843250 --- /dev/null +++ b/backup_folder @@ -0,0 +1,42 @@ +#!/bin/sh + +if [ "$(id -u)" != "0" ]; then + echo "You must be root" + exit 1 +fi + +create_backup() { + directory=$1 + filename=$2 + mksquashfs $directory $filename +} + +restore_backup() { + filename=$1 + directory=$2 + unsquashfs -f -d $directory $filename +} + +print_help() { + printf "usage:\n\t$0 (create|restore)\nexample:\n\t$0 create (folder|directory) (filename)\n\t$0 restore (filename) (folder|directory)\n" +} + +case "$1" in + "create") + if [[ "$2" == "" || "$3" == "" ]]; then + print_help + exit 1 + fi + create_backup $2 $3 + ;; + "restore") + if [[ "$2" == "" || "$3" == "" ]]; then + print_help + exit 1 + fi + restore_backup $2 $3 + ;; + *) + print_help + ;; +esac