Announcement

Collapse
No announcement yet.

BTRFS subvolume handling through a service menu

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    something I have not grasped as yet ,,,,,,is Killing this @hear .

    yesterday it was almost working ,,,,I would rite click a subvolume click the "take a subvolume snapshot" service menu , and get the kdialog password prompt enter my password and then get the kdialog saying the snapshot was created ,,,when it was NOT ,,,,,,but that just means the script was running as it dose not actually check just reply that { "Snapshot of $source made as $target" }and gave the correct $source and $target ,,,,,,it was like the line { echo -e $PASSWD | sudo -S btrfs su sn "$source" "$target" } was not getting ran.

    TODAY ,,,they(the scripts) will not even run ...I see somthing it the task bar for 1 second ,,,,,then nothing ,,,no password prompt ,,,nothing.

    hears where I am

    Code:
    vinny@vinny-Bonobo-Extreme:~/.local/share/kservices5/ServiceMenus$ ls -la
    total 16
    drwxrwxr-x 3 vinny vinny 4096 Sep 25 16:44 .
    drwxrwxr-x 3 vinny vinny 4096 Sep 23 14:47 ..
    -rwxr-xr-x 1 vinny vinny  783 Sep 25 16:44 snapshot-manager.desktop
    drwxrwxr-x 2 vinny vinny 4096 Sep 25 16:42 snapshot_manager-scripts
    Code:
    vinny@vinny-Bonobo-Extreme:~/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts$ ls -la
    total 20
    drwxrwxr-x 2 vinny vinny 4096 Sep 25 16:42 .
    drwxrwxr-x 3 vinny vinny 4096 Sep 25 16:44 ..
    -rwxr-xr-x 1 vinny vinny 1031 Sep 25 16:36 delete_subvol
    -rwxr-xr-x 1 vinny vinny  316 Sep 25 16:42 is_subvol
    -rwxr-xr-x 1 vinny vinny  728 Sep 25 16:34 snapshot_subvol
    snapshot-manager.desktop,,,,,,,,,,,,,,,,,,,,,

    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=/home/vinny/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts/is_subvol %U
    
    [Desktop Action takesnapshot]
    Icon=camera-photo
    Name=Take a Subvolume Snapshot
    Exec=/home/vinny/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts/snapshot_subvol %U
    
    [Desktop Action deletesubvol]
    Icon=user-trash-full
    Name=Permanently Delete a Subvolume
    Exec=/home/vinny/.local/share/kservices5/ServiceMenus/snapshot_manager-scripts/delete_subvol %U
    snapshot_subvol text
    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
    the subvolumes are in the 1TB drive mounted at /mnt/btrfs at boot with this line in /etc/fstab,,,,,,,,,,,,,,,,,

    Code:
    #TB-drive
    /dev/sdb1 /mnt/btrfs    btrfs     rw,relatime,space_cache,compress=lzo     0    0
    if I do a,,,,,,,,,

    Code:
    vinny@vinny-Bonobo-Extreme:/mnt/btrfs$ sudo -A btrfs sub snap @home/ /mnt/btrfs/@home-snap
    the snapshot gets created ,,,,,,and sudo gives a popup for the password because of the -A switch .

    Code:
    vinny@vinny-Bonobo-Extreme:~$ ls -la /mnt/btrfs
    total 8
    drwxr-xr-x 1 root  root   118 Sep 24 01:55 .
    drwxr-xr-x 4 root  root  4096 Aug 22 22:08 ..
    drwxr-xr-x 1 root  root   184 Dec 17  2016 @
    drwxr-xr-x 1 root  root    30 Dec 17  2016 @home
    drwxr-xr-x 1 root  root    30 Dec 17  2016 @home-snap
    drwxr-xr-x 1 vinny vinny  194 Jul 26 22:57 kubuntu
    drwxr-xr-x 1 root  root    60 Dec 17  2016 ubiquity-apt-clone
    drwxr-xr-x 1 root  root     6 Dec 17  2016 var
    -rw-rw-r-- 1 vinny vinny    2 Jan 28  2016 .windows-serial
    I just got home from work ,,,and tired ,,,must get food ,,,,,,,

    VINNY
    i7 4core HT 8MB L3 2.9GHz
    16GB RAM
    Nvidia GTX 860M 4GB RAM 1152 cuda cores

    Comment


      #17
      OK sweet ,,,,,,it's working just great now ,,,,,I do not know why yesterday it was not ,,,,,but I do know why it was giving me trouble today ...the shabang was 1 space out ,,,from the copy and paste operation

      vary nice @oshunluvr very nice indeed

      I will be keeping this one ,,,even the "is_subvol" is correctly identifying that a directory is not a subvolume today ,,,,yesterday it was saying anything I clicked on was a subvolume ??

      obviously something I did wrong

      VINNY
      i7 4core HT 8MB L3 2.9GHz
      16GB RAM
      Nvidia GTX 860M 4GB RAM 1152 cuda cores

      Comment


        #18
        Originally posted by vinnywright View Post
        ... ,,,,,but I do know why it was giving me trouble today ...the shabang was 1 space out ,,,from the copy and paste operation ...

        VINNY
        Vinny, if you keep making the same kinds of mistakes we coders make then we'll be forced to give you your official coder badge!

        (IOW, been there, done that! )
        "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
        – John F. Kennedy, February 26, 1962.

        Comment


          #19
          Originally posted by GreyGeek View Post
          Vinny, if you keep making the same kinds of mistakes we coders make then we'll be forced to give you your official coder badge!

          (IOW, been there, done that! )
          LOL ,,,,O heck ,,,thank you for the vote of confidence ,,,but I am a loooooong way off from being a coder like you their O venerable one Mr. GG

          VINNY
          i7 4core HT 8MB L3 2.9GHz
          16GB RAM
          Nvidia GTX 860M 4GB RAM 1152 cuda cores

          Comment


            #20
            Coder Badge... is that a pocket protector?
            If you think Education is expensive, try ignorance.

            The difference between genius and stupidity is genius has limits.

            Comment


              #21
              BTRFS subvolume handling through a service menu

              Shhhhhh!
              ***shading mouth with hand and whispering*** and tape on the nose bridge of his glasses!
              "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
              – John F. Kennedy, February 26, 1962.

              Comment


                #22
                LOL you guys - Glad you figured it out Vinny. I added a read-only snapshot menu item today - just copied the snapshot script and added the -r switch and changed the name, then added the menu item for it.

                Next up will be a send|receive menu item. This will probably take some work...

                Please Read Me

                Comment


                  #23
                  Originally posted by oshunluvr View Post
                  LOL you guys - Glad you figured it out Vinny. I added a read-only snapshot menu item today - just copied the snapshot script and added the -r switch and changed the name, then added the menu item for it.

                  Next up will be a send|receive menu item. This will probably take some work...
                  Oooo I have no need for the send/receive ,,,,no extra drives to send it to ,,,,,but you mite make use of the "kdialog --getexistingdirectory" to chose one ,,,,it was working in one of my edits to your scripts...as far as using it to select $source and $target,,,,,,,,,

                  think I'll just add the -r switch to the existing as thats the most useful to me for making a "restore" point before a ,,,,,,,? potentially dangerous to the system experiment as I am known to do ,,,, but wait don't you need to use the "send/receive to re make it "rw" to restore it ,,,,LOL ,,,,may be I do need your work in progress their .

                  VINNY
                  i7 4core HT 8MB L3 2.9GHz
                  16GB RAM
                  Nvidia GTX 860M 4GB RAM 1152 cuda cores

                  Comment


                    #24
                    Really IMO, the only purpose for a read-only subvolume is so you can send it. Any subvolume snapshot you take will not be modified unless you enter the subvolume manually and edit something in it. If you're going to "restore" a subvolume from a read-only snapshot, you'd have to re-snapshot the read-only snapshot as a read-write snapshot or modify the snapshot properties. Seems to me like an extra step with no real benefit.

                    Anyway, I'm working on the send|receive and I cannot get this statement to work:
                    Code:
                    if [[ "$(echo -e $PASSWD | sudo -S btrfs property get -ts "$source")" -ne "ro=true" ]]; then
                    The command works perfectly from a bash prompt and apparently in the script, but I can't get the evaluation ( not equal to ro=true) to work in the script.

                    Drivin' me batty.

                    Please Read Me

                    Comment


                      #25
                      BTRFS subvolume handling through a service menu

                      Assign the sudo cmd to a var before the if test and then inside the if test:
                      exec $var

                      Worth a try


                      Sent from my iPhone using Tapatalk
                      "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                      – John F. Kennedy, February 26, 1962.

                      Comment


                        #26
                        Expanded it to this and now it works:
                        Code:
                        tester=`echo -e $PASSWD | sudo -S btrfs property get -ts "$source"`
                        tester=${tester: -4}
                        
                        if [[ $tester != "true" ]]; then
                            kdialog --error "Sorry, This is not a READ_ONLY BTRFS Subvolume."
                            exit 0
                        fi
                        I couldn't get it to work combined. It also turned out the "sudo -S property..." part would return "ro=true" (or false) except on the first run when it would return "[sudo] password for stuart: ro=true" so I had to trim the output to the last 4 letters.

                        Please Read Me

                        Comment


                          #27
                          Here's a new is_subvol script that will show you read-only on ro snapshots:
                          Code:
                          #!/bin/bash# is_subvol v2
                          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"
                              exit 0
                          fi
                          
                          
                          #identify if subvolume is read-only snapshot
                          isreadonly=`btrfs property get -ts "$source"`
                          isreadonly=${isreadonly: -4}
                          
                          
                          if [[ $isreadonly = "true" ]]; then
                              kdialog --msgbox "This folder is a READ-ONLY btrfs Subvolume."
                          else
                          kdialog --msgbox "This folder is a btrfs Subvolume."
                          fi
                          
                          
                          exit 0

                          Please Read Me

                          Comment


                            #28
                            Here's a send_receive_subvol script that seems to work:
                            Code:
                            #!/bin/bash# send_receive_subvol
                            source="$1"
                            
                            
                            # get the sudo password
                            PASSWD="$(kdialog --password "This task requires SUDO access. Please enter your password: ")"
                            
                            
                            #allow cancel to exit cleanly 
                            if [ -z "$PASSWD" ]; then 
                            kdialog --passivepopup "Send|Receive cancelled" 6
                            exit 0; fi
                            
                            
                            #verify btrfs subvolume and exit if not
                            if [[ "$(stat -f --format="%T" "$source")" -ne "btrfs" ]] || [[ "$(stat --format="%i" "$source")" -ne 256 ]]
                            then
                                kdialog --error "Sorry, This is not a BTRFS Subvolume."
                                exit 0
                            fi
                            
                            
                            #verify subvolume is read-only snapshot
                            isreadonly=`btrfs property get -ts "$source"`
                            isreadonly=${isreadonly: -4}
                            
                            
                            if [[ $isreadonly != "true" ]]; then
                                kdialog --error "Sorry, This is not a READ_ONLY BTRFS Subvolume."
                                exit 0
                            fi
                            
                            
                            #pick your destination
                            target=`kdialog --title "Please select a folder to receive the snapshot" --getexistingdirectory / `
                            
                            
                            #verify destination is btrfs file system
                            if [[ "$(stat -f --format="%T" "$target")" -ne "btrfs" ]] || [[ "$(stat --format="%i" "$target")" -ne 256 ]]
                            then
                                kdialog --error "Sorry, This is not a BTRFS file system location."
                                exit 0
                            fi
                              
                            #last chance to quit
                            kdialog --title "Send|Receive this snapshot"\
                             --warningcontinuecancel "Depending on the size of this subvolume, this operation could take quite a while..."\
                             --continue-label "...Send snapshot"\
                             --cancel-label "...Cancel this operation"
                            
                            
                            #send cancel message to notifications and exit
                            if [ "$?" = 1 ]; then 
                            kdialog --passivepopup "Send|Receive operation cancelled" 6
                            exit 0; fi
                            
                            
                            # finally begin the send|receive operation, notify passively, then exit
                            kdialog --passivepopup "Subvolume $source is now being sent to $target" 8
                            echo -e $PASSWD | sudo -S btrfs send "$source" | sudo -S btrfs receive "$target"
                            kdialog --passivepopup "Subvolume $source send|receive operation to $target is complete" 12
                            
                            
                            exit 0

                            Please Read Me

                            Comment


                              #29
                              I wish I could figure out how to get the notifications from notify-send or kdialog into the Plasma Notifications window. These passivepopup messages do not go into the tray notifications box so you can't review them.

                              Please Read Me

                              Comment


                                #30
                                Originally posted by oshunluvr View Post
                                I wish I could figure out how to get the notifications from notify-send or kdialog into the Plasma Notifications window. These passivepopup messages do not go into the tray notifications box so you can't review them.
                                "wall" would work ,,,,,,,pipe the output through "wall" and see

                                VINNY

                                EDIT: it works ,,,,but kind of clutsy ,,,you get a "bell in message bus" then the info ...this by replacing "kdialog --msgbox "This folder is a BTRFS Subvolume." "

                                with "wall "This folder is a BTRFS Subvolume." "
                                Last edited by vinnywright; Sep 27, 2017, 02:40 PM.
                                i7 4core HT 8MB L3 2.9GHz
                                16GB RAM
                                Nvidia GTX 860M 4GB RAM 1152 cuda cores

                                Comment

                                Working...
                                X