From 2bde7ce22406e0232e513235c4317cb762a24c6e Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Sat, 1 Aug 2020 09:52:21 +0300 Subject: [PATCH 1/8] Update README.md Added requirements --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fbb6230..2bcd3a5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # snapsh -Btrfs snapshot managing script +Btrfs snapshot managing bash script + +###### Requirements: +- `bash` +- GNU `setopt` - part of GNU `coreutils` +- `btrfs-progs`- Userspace programs for btrfs -- 2.40.1 From 4d4dcb311bf4edf0db0335d063a4c588cad3c80b Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Sat, 1 Aug 2020 20:19:47 +0300 Subject: [PATCH 2/8] Update README.md Added configuration and basic snapshotting instructions --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2bcd3a5..a2adbb4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # snapsh Btrfs snapshot managing bash script -###### Requirements: +### Requirements: - `bash` - GNU `setopt` - part of GNU `coreutils` - `btrfs-progs`- Userspace programs for btrfs + +### Instructions: +- Script needs the toplevel subvolume (id=5) mounted somewhere. Default location is `/root/btrfs-toplevel`, but you can mount it anywhere you like and define it with `TOPLEVEL` variable. (A separate config file will be implemented later). +- Will create a subvolume named snapshots by default to the toplevel. This can also be changed with `SNAPSHOTS_LOCATION`. +- Display usage instructions with `snapsh -h` or `snapsh --help` +- Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`) -- 2.40.1 From 3a1a0c9800a265e1ac18e81f5111b0577659c43a Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Sat, 1 Aug 2020 20:43:54 +0300 Subject: [PATCH 3/8] Update README.md Instructions for adding description added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2adbb4..cf65405 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Btrfs snapshot managing bash script - Script needs the toplevel subvolume (id=5) mounted somewhere. Default location is `/root/btrfs-toplevel`, but you can mount it anywhere you like and define it with `TOPLEVEL` variable. (A separate config file will be implemented later). - Will create a subvolume named snapshots by default to the toplevel. This can also be changed with `SNAPSHOTS_LOCATION`. - Display usage instructions with `snapsh -h` or `snapsh --help` -- Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`) +- Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. You can add a description for the snapshot with the `-d | --description` option (must be used before the `-s` option)

Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -d "This is a snapshot" -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`), with a description "This is a snapshot" -- 2.40.1 From 8db86b51ec9245477d7c0d58223c2f62ca01563e Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Sun, 2 Aug 2020 20:32:41 +0300 Subject: [PATCH 4/8] Update README.md Added list option description --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cf65405..0c00b14 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,4 @@ Btrfs snapshot managing bash script - Will create a subvolume named snapshots by default to the toplevel. This can also be changed with `SNAPSHOTS_LOCATION`. - Display usage instructions with `snapsh -h` or `snapsh --help` - Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. You can add a description for the snapshot with the `-d | --description` option (must be used before the `-s` option)

Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -d "This is a snapshot" -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`), with a description "This is a snapshot" +- Snapshots can be listed with `snapsh -l` or `snapsh --list` -- 2.40.1 From 8e4de6a074d08195d8ebdc1ea3315fdcc72a1ee2 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Sun, 2 Aug 2020 21:47:27 +0300 Subject: [PATCH 5/8] Update README.md Added information for snapshot deletion. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0c00b14..6c89ef2 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,4 @@ Btrfs snapshot managing bash script - Display usage instructions with `snapsh -h` or `snapsh --help` - Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. You can add a description for the snapshot with the `-d | --description` option (must be used before the `-s` option)

Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -d "This is a snapshot" -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`), with a description "This is a snapshot" - Snapshots can be listed with `snapsh -l` or `snapsh --list` +- Delete snapshots with the `-r` or `--remove` option. List snapshots first with `snapsh -l`, then delete snapshot with e.g. `snapsh -r 2`, where 2 is the number of the deletable snapshot in the `-l` listing. The list numbers always start from 1 and increment from there, so always check the number before deletion. Batch deletion might be implemented later. -- 2.40.1 From 5870065f0cefb0aa1c3436d6b190e98a923d5c51 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Sun, 2 Aug 2020 22:01:49 +0300 Subject: [PATCH 6/8] Update README.md Added planned features and license --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 6c89ef2..e8387f7 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,16 @@ Btrfs snapshot managing bash script - Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. You can add a description for the snapshot with the `-d | --description` option (must be used before the `-s` option)

Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -d "This is a snapshot" -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`), with a description "This is a snapshot" - Snapshots can be listed with `snapsh -l` or `snapsh --list` - Delete snapshots with the `-r` or `--remove` option. List snapshots first with `snapsh -l`, then delete snapshot with e.g. `snapsh -r 2`, where 2 is the number of the deletable snapshot in the `-l` listing. The list numbers always start from 1 and increment from there, so always check the number before deletion. Batch deletion might be implemented later. + +### Planned features: +- separate config file +- `--install` option to integrate script into system +- Batch deletion of snapshots +- `systemd` timer for automating snapshots +- `--auto` option (quiet) for automated snapshots +- Option to snapshot multiple/all subvolumes + +Root access is required for `btrfs-progs`. + +### License: +GPL v3.0 -- 2.40.1 From cfabe5d30b8f8860aa18c20104d74e3fc2faf796 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen <50285623+0ranki@users.noreply.github.com> Date: Wed, 5 Aug 2020 00:30:01 +0300 Subject: [PATCH 7/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e8387f7..9e30707 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Btrfs snapshot managing bash script - Taking snapshots requires root priviledges. Take a snapshot with `snapsh -s SUBVOLUME` or `snapsh --snapshot SUBVOLUME`, where `SUBVOLUME` is the name of the source subvolume. You can add a description for the snapshot with the `-d | --description` option (must be used before the `-s` option)

Example with Fedora default btrfs layout with `root` and `home` subvolumes:
`snapsh -d "This is a snapshot" -s root`
This will create a snapshot called `root_snapshot_YYYY.MM.DD-hh:mm:ss` to the `snapshots` subvolume (or the one you defined with `SNAPSHOTS_LOCATION`), with a description "This is a snapshot" - Snapshots can be listed with `snapsh -l` or `snapsh --list` - Delete snapshots with the `-r` or `--remove` option. List snapshots first with `snapsh -l`, then delete snapshot with e.g. `snapsh -r 2`, where 2 is the number of the deletable snapshot in the `-l` listing. The list numbers always start from 1 and increment from there, so always check the number before deletion. Batch deletion might be implemented later. +- Rollback to a snapshot with `snapsh --rollback NUMBER`, where NUMBER is the number listed in `snapsh -l`. The subvolume will be detected from the snapshot. E.g. `snapsh --rollback 14`. Script will ask to reboot system once done. ### Planned features: - separate config file -- 2.40.1 From 10b221be188206843f58c47f527cabc5b19e1991 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Wed, 5 Aug 2020 08:40:31 +0300 Subject: [PATCH 8/8] Fixed rebooting after rollback Fixed typo in systemctl reboot call after rollback --- snapsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snapsh b/snapsh index 97ddcbb..b2705f1 100755 --- a/snapsh +++ b/snapsh @@ -182,9 +182,9 @@ rollback() { read -n 1 if [[ "${REPLY}" == "y" ]]; then - systemctl restart & exit 0 + systemctl reboot & exit 0 else - printf "\nPlease restart system as soon as possible. Any changes to\nsubvolume ${SOURCE_SUBVOLUME} will not persist after rebooting.\n" + printf "\nPlease restart system as soon as possible. Any changes to subvolume ${SOURCE_SUBVOLUME} will not persist after rebooting.\n" exit 1 fi -- 2.40.1