I went back and edited the first post to make sure I chad the code there the most current. I noticed Vinny had the previous version in the "is_subvol" script (just a housekeeping change that shortened the content)
Vinny, make sure you have a blank line at the end of all the scripts too. Bash can be picky.
Announcement
Collapse
No announcement yet.
BTRFS subvolume handling through a service menu
Collapse
This topic is closed.
X
X
-
Here's a video of it working here. I tried it on multiple locations and it worked every time.
https://www.dropbox.com/s/pn1iupbwhx...nager.mp4?dl=0
- Top
- Bottom
Leave a comment:
-
It works here. I shouldn't have assumed you'd know to mount the parent first - but if you're taking a snapshot you have to mount the parent or else you can't "see" the subvolume to snapshot it in the first place.
Make sure all the scripts are executable ( chmod +x script_name ) and either use the same folder name I did or edit the desktop file to reflect the correct location.
Let me try it again here on a different location and make sure I didn't miss something...
- Top
- Bottom
Leave a comment:
-
Originally posted by GreyGeek View PostThe "snapshot_subvol" script does not mount /mnt/btrfs. Is that mounted all the time on your system?
this dose work now for the "is_subvol" check ,,,,,,,,,,,,,,,,,,,
Code:#!/bin/bash #source="$1" #just check, notify and exit #this dosent work for what we want as it's "stating" for FILESYSYTEM and will return "btrfs" for anything in the filesystem (we are cheking in a btrfs filesystem after all) :) #[[ "$(stat -f --format="%T" "$source")" -ne "btrfs" ]] || source="$(kdialog --getexistingdirectory .)" if [ "$(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
VINNY
- Top
- Bottom
Leave a comment:
-
Originally posted by GreyGeek View PostThe "snapshot_subvol" script does not mount /mnt/btrfs. Is that mounted all the time on your system?
I didn't see anywhere in the scripts where the ROOT of the Btrfs pool is mounted to /mnt, so I am not surprised that the script didn't work.
- Top
- Bottom
Leave a comment:
-
Originally posted by vinnywright View Postdose not seem to be working @hear ,,,,,,,,
the "is this a subvolume" said yes whether it was , or just a folder in the drive .
the "take a subvolume snapshot" ,,,gives a dialog that it created the sub snap at /mnt/btrfs/@home-<date string> ,,,,but did not ?
I get
Code:vinny@vinny-Bonobo-Extreme:/mnt/btrfs$ sudo btrfs sub list -a /mnt/btrfs ID 1175 gen 54771 top level 5 path @ ID 1176 gen 54770 top level 5 path @home
VINNY
I didn't see anywhere in the scripts where the ROOT of the Btrfs pool is mounted to /mnt, so I am not surprised that the script didn't work.
- Top
- Bottom
Leave a comment:
-
I was just trying to figure out how to add Lubuntu 14.04 as dual boot along side Kubuntu 14.04 in my same btrfs full drive. I created a subvolume for @Kubuntu1404 and @home1404 for @ and @home. I was looking up how to delete the originals when I saw this. I will add it after the great and all powerful Kubuntu god of btrfs (oshunluvr) fixes it.
- Top
- Bottom
Leave a comment:
-
dose not seem to be working @hear ,,,,,,,,
the "is this a subvolume" said yes whether it was , or just a folder in the drive .
the "take a subvolume snapshot" ,,,gives a dialog that it created the sub snap at /mnt/btrfs/@home-<date string> ,,,,but did not ?
I get
Code:vinny@vinny-Bonobo-Extreme:/mnt/btrfs$ sudo btrfs sub list -a /mnt/btrfs ID 1175 gen 54771 top level 5 path @ ID 1176 gen 54770 top level 5 path @home
VINNY
- Top
- Bottom
Leave a comment:
-
My first step would have to be mounting/dev/sda1 to /mnt and /dev/sdb1 to / backup. Then an option to do a time stamped to subvolume of @ and @home to /mnt/snapshots with sync and an option to send those snapshots to /backup followed by a umount.
I never create snapshots inside / or /home
Sent from my iPhone using Tapatalk
- Top
- Bottom
Leave a comment:
-
Originally posted by oshunluvr View PostThanks again Vinny - I couldn't do it without ya!
and I like it ,,,,will try it @hear ,,,,after I finish the yard
VINNY
- Top
- Bottom
Leave a comment:
-
I'm going to add this ,,,,after you fix the "del_subvol" script file: ,,,,right now it's the "is_subvol" script file: re-coped
VINNY
- Top
- Bottom
Leave a comment:
-
BTRFS subvolume handling through a service menu
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:
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[/#]Last edited by oshunluvr; Aug 14, 2018, 05:47 AM.
Users Viewing This Topic
Collapse
There are 0 users viewing this topic.
Leave a comment: