I like using Dolphin so I added this service menu and tasks to my Dolphin this morning. Feel free to make it your own and if you're a bash scripting guru, please comment on improvements. I'm also open to new features that would be useful.
For now, I can create snapshots and delete subvolumes. I also included an "Is it a BTRFS Subvolume" test in case you don't always use the "@" to lead your subvolume names and aren't sure which is a folder and which is a subvolume. Regardless, the scripts validate that before acting.
Here's the contents of the files I wrote this morning. All of them are under ~/.local/share/kservices5/ServiceMenus. The bash scripts are in a folder there call "snapshot_manager-scripts"
"snapshot-manager" service manager desktop file:
"is_subvol" script file:
"snapshot_subvol" script file:
"delete_subvol" script file:
This should be obvious but "USE AT YOUR OWN RISK"
I tested it many times before posting, but you never know how it going to end up on your system.
Also, the "To Do" list so far:
[#]btrfs[/#] [#]subvolume[/#] [#]servicemenu[/#]
For now, I can create snapshots and delete subvolumes. I also included an "Is it a BTRFS Subvolume" test in case you don't always use the "@" to lead your subvolume names and aren't sure which is a folder and which is a subvolume. Regardless, the scripts validate that before acting.
Here's the contents of the files I wrote this morning. All of them are under ~/.local/share/kservices5/ServiceMenus. The bash scripts are in a folder there call "snapshot_manager-scripts"
"snapshot-manager" service manager desktop file:
Code:
[Desktop Entry] Type=Service Actions=issubvol;_SEPARATOR_;takesnapshot;deletesubvol X-KDE-ServiceTypes=KonqPopupMenu/Plugin,inode/directory MimeType=inode/directory; X-KDE-StartupNotify=false X-KDE-Priority=TopLevel X-KDE-Submenu=Manage BTRFS Subvolumes [Desktop Action issubvol] Icon=question Name=Is this a BTRFS Subvolume Exec=~/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts/is_subvol %U [Desktop Action takesnapshot] Icon=camera-photo Name=Take a Subvolume Snapshot Exec=~/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts/snapshot_subvol %U [Desktop Action deletesubvol] Icon=user-trash-full Name=Permanently Delete a Subvolume Exec=~/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts/delete_subvol %U
Code:
#!/bin/bash# is_subvol source="$1" #just check, notify and exit if [[ "$(stat -f --format="%T" "$source")" -ne "btrfs" ]] || [[ "$(stat --format="%i" "$source")" -ne 256 ]] then kdialog --error "Sorry, This is not a BTRFS Subvolume" else kdialog --msgbox "This folder is a BTRFS Subvolume." fi exit 0
Code:
#!/bin/bash# snapshot_subvol source="$1" target="$1"_`date +%y%m%d-%H%M%S` # get the sudo password PASSWD="$(kdialog --password "This task requires SUDO access. Enter your password: ")" #allow cancel to exit cleanly if [ -z "$PASSWD" ]; then kdialog --passivepopup "Snapshot cancelled" 6 exit 0; fi #validate target is actually a btrfs subvolume and exit if not if [[ "$(stat -f --format="%T" "$source")" -ne "btrfs" ]] || [[ "$(stat --format="%i" "$source")" -ne 256 ]] then kdialog --error "Sorry, Not a BTRFS Subvolume" exit 0 fi #take the snapshot, passively notify, and exit echo -e $PASSWD | sudo -S btrfs su sn "$source" "$target" kdialog --passivepopup "Snapshot of $source made as $target" 6 exit 0
Code:
#!/bin/bash# delete_subvol source="$1" PASSWD="$(kdialog --password "This task requires SUDO access. Enter your password: ")" if [ -z "$PASSWD" ]; then kdialog --passivepopup "Subvolume deletion cancelled" 6 exit 0; fi #validate target is actually a btrfs subvolume if [[ "$(stat -f --format="%T" "$source")" -ne "btrfs" ]] || [[ "$(stat --format="%i" "$source")" -ne 256 ]] then kdialog --error "Sorry, Not a BTRFS Subvolume" exit 0 fi #last chance to quit, buttons reversed so Cancel is default action kdialog --title "THIS ACTION IS NOT REVERSIBLE"\ --warningcontinuecancel "Are you sure you want to delete all this subvolume?"\ --cancel-label "PERMANENTLY DELETE"\ --continue-label "Cancel" #send cancel message to notifications and exit if [ "$?" = 0 ]; then kdialog --passivepopup "Subvolume deletion cancelled" 6 exit 0; fi # finally delete the subvolume and notify passively then exit echo -e $PASSWD | sudo -S btrfs su de -c "$source" kdialog --passivepopup "Subvolume $source deleted" 8 exit 0
I tested it many times before posting, but you never know how it going to end up on your system.
Also, the "To Do" list so far:
- Make functions work with more than one subvolume at a time.
- Add check to determine snapshot vs. parent subvolume.
- Yours??
[#]btrfs[/#] [#]subvolume[/#] [#]servicemenu[/#]
Comment