Jarno Rankinen
b8bd2d026d
Script asks if the user wants to do a filesystem relabeling at the next reboot. If SElinux policies were updated between the current state and the rollback target, this seemed to cause an issue where no user could login. Disabling SElinux or relabeling fixes the problem. |
||
---|---|---|
LICENSE | ||
README.md | ||
snapsh | ||
snapsh-post-rollback.service | ||
snapsh.conf |
README.md
snapsh
Btrfs snapshot managing bash script
Requirements:
bash
- GNU
setopt
- part of GNUcoreutils
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 withTOPLEVEL
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
orsnapsh --help
- Taking snapshots requires root priviledges. Take a snapshot with
snapsh -s SUBVOLUME
orsnapsh --snapshot SUBVOLUME
, whereSUBVOLUME
is the name of the source subvolume. You can add a description for the snapshot with the-d | --description
option
Example with Fedora default btrfs layout withroot
andhome
subvolumes:
snapsh -s root -d "This is a snapshot"
This will create a snapshot calledroot_snapshot_YYYY.MM.DD-hh:mm:ss
to thesnapshots
subvolume (or the one you defined withSNAPSHOTS_LOCATION
), with a description "This is a snapshot" - Snapshots can be listed with
snapsh -l
orsnapsh --list
- Delete snapshots with the
-r
or--remove
option. List snapshots first withsnapsh -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 insnapsh -l
. The subvolume will be detected from the snapshot. E.g.snapsh --rollback 14
. Script will ask to reboot system once done.- Rollback renames your currently active subvolume to SUBVOLUME.backup, if you want these backups to be deleted automatically, copy the included
snapsh-post-rollback.service
to/etc/systemd/system
andsystemctl enable snapsh-post-rollback.service
. It will check if*.backup
subvolumes exist and delete them on every boot. This is recommended to be enabled, since rollbacks also take a "regular" readonly snapshot asSUBVOLUME_backup_YYYY.MM.DD-hh:mm:ss
. The unit will be enabled automatically with the--install
option which will be done later.
- Rollback renames your currently active subvolume to SUBVOLUME.backup, if you want these backups to be deleted automatically, copy the included
- Snapshot type displayed in listing can be set with the
-t, --type
option. When used in conjunction with-l | --list
, it will filter the results based on the type. E.g.snapsh -l -t manual
will list all the snapshots with the typemanual
. Type can be one ofmanual, auto, boot
orbackup
. Note that onlymanual
andbackup
are implemented properly at this stage, but you can still use the other types as well.
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