added backup disk and backup folder directory

This commit is contained in:
wt
2025-03-19 13:36:57 +07:00
commit cd4a366d24
2 changed files with 85 additions and 0 deletions
Executable
+43
View File
@@ -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
Executable
+42
View File
@@ -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