rsnapshot / rsnapshot

a tool for backing up your data using rsync (if you want to get help, use https://lists.sourceforge.net/lists/listinfo/rsnapshot-discuss)
http://rsnapshot.org
GNU General Public License v2.0
3.23k stars 263 forks source link

remove of LV snapshot not happening if mount error #39

Closed Napsty closed 9 years ago

Napsty commented 10 years ago

I was looking in existing bug reports / issues if this problem was already mentioned but couldn't find anything. Please close this issue and point me to existing the bug report if there is one.

It appears that rsnapshot does not remove a logical volume snapshot if the snapshot could not be mounted. See the following log:

[10/Sep/2014:02:07:43] /sbin/lvcreate --snapshot --size 200M --name rsnapshot /dev/vgdata/mylv
[10/Sep/2014:02:07:44] /bin/mount /dev/vgdata/rsnapshot /mnt/lvm-snapshot
[10/Sep/2014:02:07:44] /usr/bin/rsnapshot -c /etc/rsnapshot.backup.conf daily: ERROR: Mount LVM snapshot failed: 8192
[10/Sep/2014:02:07:44] rm -f /var/run/rsnapshot.pid

Reason for the mount error was, that the mountpoint (/mnt/lvm-snapshot) didn't exist. In the log you see, that the snapshot was not removed.

On the next run of rsnapshot, the creation of the LV snapshot failed, because it already existed (from the previous run):

[10/Sep/2014:09:30:08] /sbin/lvcreate --snapshot --size 200M --name rsnapshot /dev/vgdata/mvlv
[10/Sep/2014:09:30:08] /usr/bin/rsnapshot -c /etc/rsnapshot.backup.conf daily: ERROR: Create LVM snapshot failed: 1280
[10/Sep/2014:09:30:08] rm -f /var/run/rsnapshot.pid

The created LVM snapshot should have been removed in the first run when the mount error appeared.

Or verify that the defined mountpoint for LVM snapshots does exist when rsnapshot starts up. If the mount point is not found, throw error and exit rsnapshot without doing anything.

bebehei commented 9 years ago

Thanks for the report.

Just two questions, to support us: What version have you used? Does it occur with current master, too?

Napsty commented 9 years ago

This bug occurred with rsnapshot 1.3.1 on an Ubuntu 14.04 LTS server. I just tested it again (with the latest Ubuntu 14.04.02 installation) and the issue still remains in Ubuntu.

I also tested it with the current master and the issue still exists.

/usr/local/bin/rsnapshot version
rsnapshot 1.3.1-140-g6433982

/usr/local/bin/rsnapshot alpha
[...]
/sbin/lvcreate --snapshot --size 100M --name rsnapshot /dev/vgroot/lvdata
/bin/mount /dev/vgroot/rsnapshot /mnt/lvm-snapshot
mount: mount point /mnt/lvm-snapshot does not exist
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot alpha
----------------------------------------------------------------------------
ERROR: Mount LVM snapshot failed: 8192
/usr/bin/logger -p user.err -t rsnapshot[19211] /usr/local/bin/rsnapshot \
    alpha: ERROR: Mount LVM snapshot failed: 8192
rm -f /var/run/rsnapshot.pid

The LVM snapshot is till taken:

lvs
  LV        VG     Attr      LSize   Pool Origin Data%  Move Log Copy%  Convert
  lvdata    vgroot owi-a-s--   2.79g
  lvroot    vgroot -wi-ao---   4.66g
  lvvar     vgroot -wi-ao---   3.72g
  rsnapshot vgroot swi-a-s-- 100.00m      lvdata   0.00
  vgtmp     vgroot -wi-ao---   1.86g

Then in the next run, after having created the missing mount directory:

mkdir /mnt/lvm-snapshot

/usr/local/bin/rsnapshot alpha
[...]
/sbin/lvcreate --snapshot --size 100M --name rsnapshot /dev/vgroot/lvdata
  Logical volume "rsnapshot" already exists in volume group "vgroot"
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot alpha
----------------------------------------------------------------------------
ERROR: Create LVM snapshot failed: 1280
/usr/bin/logger -p user.err -t rsnapshot[19281] /usr/local/bin/rsnapshot \
    alpha: ERROR: Create LVM snapshot failed: 1280
rm -f /var/run/rsnapshot.pid
bebehei commented 9 years ago

Ok, I'm working right now on it. I wouldn't say it is duplicate, but your issue is quite similar to #35 and probably both issues will get solved with one single PR. Right now I'm working on this at: https://github.com/bebehei/rsnapshot/tree/issue/35-unmount-lvm-after-fail

It would be nice if you have a look over it and maybe test it. Please don't run it with your production data.

Napsty commented 9 years ago

I tested now again with the current master branch with including your commit 6f9037b5c116c6e2268e3b0c247370b65d0c5a49.

 /usr/local/bin/rsnapshot version
rsnapshot 1.3.1-142-g2888dbc

rsnapshot run:

# /usr/local/bin/rsnapshot alpha
[...]
/sbin/lvcreate --snapshot --size 100M --name rsnapshot \
    /dev/rsnapshotubuntu-vg/test
/bin/mount /dev/rsnapshotubuntu-vg/rsnapshot /mnt/lvm-snapshot
mount: mount point /mnt/lvm-snapshot does not exist
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot alpha
----------------------------------------------------------------------------
ERROR: Mount LVM snapshot failed: 8192
/usr/bin/logger -p user.err -t rsnapshot[19677] /usr/local/bin/rsnapshot \
    alpha: ERROR: Mount LVM snapshot failed: 8192
/sbin/lvremove --force /dev/rsnapshotubuntu-vg/rsnapshot
rm -f /var/run/rsnapshot.pid

And the LVM snapshot was properly removed (lvremove):

 lvs
  LV   VG                 Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  root rsnapshotubuntu-vg -wi-ao--- 17.74g
  test rsnapshotubuntu-vg -wi-a----  1.00g

So now I create the mount point ...

mkdir /mnt/lvm-snapshot

... and run rsnapshot again:

/usr/local/bin/rsnapshot alpha
[...]
/sbin/lvcreate --snapshot --size 100M --name rsnapshot \
    /dev/rsnapshotubuntu-vg/test
/bin/mount /dev/rsnapshotubuntu-vg/rsnapshot /mnt/lvm-snapshot
chdir(/mnt/lvm-snapshot)
/usr/bin/rsync -av --delete --numeric-ids --relative --delete-excluded ./ \
    /backup/alpha.0/lvm-rsnapshotubuntu-vg/test/
sending incremental file list
created directory /backup/alpha.0/lvm-rsnapshotubuntu-vg/test
./
lost+found/

sent 75 bytes  received 89 bytes  328.00 bytes/sec
total size is 0  speedup is 0.00
rsync succeeded
chdir(/backup)
/bin/umount /mnt/lvm-snapshot
/sbin/lvremove --force /dev/rsnapshotubuntu-vg/rsnapshot
touch /backup/alpha.0/
rm -f /var/run/rsnapshot.pid
/usr/bin/logger -p user.err -t rsnapshot[19775] WARNING: \
    /usr/local/bin/rsnapshot alpha: completed, but with some warnings

So all looks good to me. Bug is fixed for me. Great job, thank you!

I will let you close this issue once you have merged the PR.

bebehei commented 9 years ago

@Napsty Thanks for reviewing it. The patch will be included in our next release. It's probably to ship in June. I don't know the release-plan for Ubuntu 15.10, but hopefully we hop into this release already with the new version.

bebehei commented 9 years ago

Will close it to gain overview. I would assume, you have no objections ;-)