From 7f3ad32c861f0dd3a9a664ac8a5ccb7e89101e96 Mon Sep 17 00:00:00 2001 From: SourLemonJuice Date: Sun, 12 Nov 2023 02:25:08 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=87=8C=E7=9A=84release=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=90=8D=E7=A7=B0=E4=B8=BA=20devtest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +-- src/config | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 18402a5..ab82d11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -/temp -/release +/devtest /.vscode diff --git a/src/config b/src/config index 1398084..8f63ff3 100644 --- a/src/config +++ b/src/config @@ -8,8 +8,8 @@ Tar_Default_Full_Backup=0 Default_Zip_Mode= # path -BackupFolder=../temp/backup -RootPath=../temp/test +BackupFolder=../devtest/backup +RootPath=../devtest/test # log -RunningLogPath=../temp/backup/.log +RunningLogPath=../devtest/backup/.log From 0af6887077768d42a1e8f90377c5215cfb054fe1 Mon Sep 17 00:00:00 2001 From: SourLemonJuice Date: Sun, 12 Nov 2023 03:40:19 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0readme=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..429ae3f --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# 文件夹备份脚本 + +这算是一个学习用的脚本了,各种地方写得都应该很差,咕咕 + +## 能干什么 + +一个(一堆)备份目录到tar文件的脚本\ +支持tar的增量备份模式(不会记录删除有什么用呢) + +## 使用 + +运行 `src/` 中的 `main.sh`,没有默认操作,需要参数\ +用`-h | --help`查看帮助信息 + +虽然脚本文件很多但主脚本中有检测文件本身路径的逻辑,不用担心不再脚本根目录执行会无法加载其他函数的问题 + +> 打包和解包前后都有提示信息,不会直接执行的 + +## 备份格式 + +未来可能有其他的方式吧 + +### tar + +> 使用`--one-file-system`参数,不会打包正常根目录里的`dev`这类文件夹 + +```text +. +├── backup +│ ├── 1699729938_2023-11-12_03-12-18 +│ │ ├── 1699729939_2023-11-12_03-12-19_backup.tar +│ │ ├── .log +│ │ ├── .snapshot +│ │ └── .template +│ ├── 1699729941_2023-11-12_03-12-21 +│ │ ├── 1699729941_2023-11-12_03-12-21_backup.tar +│ │ ├── 1699730061_2023-11-12_03-14-21_backup.tar +│ │ ├── .log +│ │ ├── .snapshot +│ │ └── .template +│ ├── .log +│ │ └── running.log +│ └── .now_backup +└── test + ├── .a + ├── a + ├── b + ├── c + ├── dev + └── lost+found +``` + +## 配置 + +### 强制使用root权限 + +可以在执行脚本前检查是否为root权限\ + +```shell +# normal +NeedRoot=0 +``` + +### 备份路径 + +`BackupFolder`是要存放备份文件的根路径\ +`RootPath`是要备份的目录 + +> 所有目录都可以使用相对路径(相对于那堆脚本文件) + +```shell +# path +BackupFolder=../devtest/backup +RootPath=../devtest/test +``` + +### tar增量备份 + +强制每次备份使用完整备份\ +关闭=不使用tar增量备份模式(-g 参数)\ + +```shell +# normal +Tar_Default_Full_Backup=0 +``` + +### 日志目录 + +设置日志存放的目录(目前没什么有用的信息啦) + +```shell +# log +RunningLogPath=../devtest/backup/.log +``` + +## 怪问题们 + +- 为什么不把东西都放到一起呀,这样多乱 + - 那就彻底看不懂了啊w + - 还有...懒,反正有配置文件在两个文件和一堆文件也没什么区别嘛 +- 为什么注释用中文,各种变量名用英文还写得稀烂 + - 因为不会英语所以要练嘛,那既然不会注释还写英文那我还写它干什么 +- 就是压缩解压一下怎么写了这么一大坨东西出来 + - 最开始是想写一个类似于定期备份系统的脚本,弄了半天才发现tar没法记录文件的删除,但已经写了按顺序解压的逻辑了就顺便把其他的东西完善一下,反正也是在学东西嘛 From 2b8365636c30c3b9462bb67c976c52e81b8d2386 Mon Sep 17 00:00:00 2001 From: SourLemonJuice Date: Sun, 12 Nov 2023 04:11:44 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E9=85=8D=E7=BD=AE=E7=9A=84=E7=A4=BA=E4=BE=8B=E4=B8=BA?= =?UTF-8?q?release=E5=88=86=E6=94=AF=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 429ae3f..feda41d 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ ```shell # normal -NeedRoot=0 +NeedRoot=1 ``` ### 备份路径 @@ -70,8 +70,8 @@ NeedRoot=0 ```shell # path -BackupFolder=../devtest/backup -RootPath=../devtest/test +BackupFolder=/usr/sys_backup +RootPath=/ ``` ### tar增量备份 @@ -81,7 +81,7 @@ RootPath=../devtest/test ```shell # normal -Tar_Default_Full_Backup=0 +Tar_Default_Full_Backup=1 ``` ### 日志目录 @@ -90,7 +90,7 @@ Tar_Default_Full_Backup=0 ```shell # log -RunningLogPath=../devtest/backup/.log +RunningLogPath=/usr/sys_backup/.log ``` ## 怪问题们 From a89d3cb4ecc821c8aa5d3666a3709e0935ed98fa Mon Sep 17 00:00:00 2001 From: SourLemonJuice Date: Sun, 12 Nov 2023 05:46:17 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/help_info | 1 + src/main.sh | 6 +++++- src/version | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/help_info b/src/help_info index 10d5708..dd012a7 100644 --- a/src/help_info +++ b/src/help_info @@ -13,3 +13,4 @@ [其他] -h,--help 获取帮助信息 +-v,--version 获取版本 diff --git a/src/main.sh b/src/main.sh index 6774cbf..57d54ee 100755 --- a/src/main.sh +++ b/src/main.sh @@ -22,7 +22,7 @@ source $ShellFilePath/restore.sh } # 获取参数 -Options=$(getopt -o hBRzf -l help,backup,restore,backup-full -- "$@") +Options=$(getopt -o vhBRzf -l version,help,backup,restore,backup-full -- "$@") if [ ! $? -eq 0 ] then echo "参数格式错误" @@ -63,6 +63,10 @@ do cat $ShellFilePath/help_info exit ;; + -v | --version) + cat $ShellFilePath/version + exit + ;; --) echo "没有执行任何参数" exit 1 diff --git a/src/version b/src/version index 9001211..38f8e88 100644 --- a/src/version +++ b/src/version @@ -1 +1 @@ -dev \ No newline at end of file +dev From f96dc9ffae13608033e0ac2f797733c06824b5c0 Mon Sep 17 00:00:00 2001 From: SourLemonJuice Date: Sun, 12 Nov 2023 06:02:35 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E6=8A=8A=E6=89=80=E6=9C=89normal=E6=94=B9=E6=88=90ord?= =?UTF-8?q?inary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index feda41d..896bc02 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ 可以在执行脚本前检查是否为root权限\ ```shell -# normal +# ordinary NeedRoot=1 ``` @@ -80,7 +80,7 @@ RootPath=/ 关闭=不使用tar增量备份模式(-g 参数)\ ```shell -# normal +# ordinary Tar_Default_Full_Backup=1 ``` diff --git a/src/config b/src/config index 8f63ff3..8afcd79 100644 --- a/src/config +++ b/src/config @@ -1,7 +1,7 @@ # 0 == false # 1 == true -# normal +# ordinary NeedRoot=0 Disable_init_Path_Detection=0 Tar_Default_Full_Backup=0 From 488b5fc48b4c1a63fbc10495a6d13ea8a3ab5292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=88=E9=85=B8=E7=9A=84=E6=9F=A0=E6=AA=AC=E6=B1=81?= <106436955+SourLemonJuice@users.noreply.github.com> Date: Sun, 12 Nov 2023 06:18:01 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=94=B9readme=E9=87=8C=E7=9A=84=E9=94=99?= =?UTF-8?q?=E5=88=AB=E5=AD=97(((?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 896bc02..dc5ee92 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ 运行 `src/` 中的 `main.sh`,没有默认操作,需要参数\ 用`-h | --help`查看帮助信息 -虽然脚本文件很多但主脚本中有检测文件本身路径的逻辑,不用担心不再脚本根目录执行会无法加载其他函数的问题 +虽然脚本文件很多但主脚本中有检测文件本身路径的逻辑,不用担心不在脚本根目录执行会无法加载其他函数的问题 > 打包和解包前后都有提示信息,不会直接执行的