teejee2008 / timeshift

System restore tool for Linux. Creates filesystem snapshots using rsync+hardlinks, or BTRFS snapshots. Supports scheduled snapshots, multiple backup levels, and exclude filters. Snapshots can be restored while system is running or from Live CD/USB.
GNU Lesser General Public License v3.0
4.69k stars 282 forks source link

Some snapshots cannot be deleted #141

Open madsherlock opened 6 years ago

madsherlock commented 6 years ago

I am trying to free up disk space by deleting old btrfs snapshots. However, deleting them from within the Timeshift GUI is impossible. They are greyed out.

The following text describes my process to force delete these snapshots, and hopefully someone will be able to find the error (if any) within Timeshift causing the problem. For a quick summary of my findings, see bottom of this post.

Here is an excerpt from the latest log of the Timeshift GUI trying to remove the oldest snapshot (already greyed out in GUI).

[11:13:25] ------------------------------------------------------------------------------
[11:13:25] Removing snapshot: 2017-09-05_15-00-01
[11:13:25] name=@home, uuid=dc2a14e2-4318-4f34-80a6-5f9fefd992a4, id=323, path=/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home
[11:13:25] Deleting subvolume: @home
[11:13:25] btrfs subvolume delete --commit-after '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home'
[11:13:25] E: Failed to delete snapshot subvolume: '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home'
[11:13:25] E: Failed to remove snapshot: 2017-09-05_15-00-01
[11:13:25] ------------------------------------------------------------------------------

I tried running the btrfs command directly as root, and got the following output:

$ sudo btrfs subvolume delete --commit-after '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home'
Delete subvolume (commit): '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home'
ERROR: cannot delete '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home': Directory not empty

So, the "directory is not empty". I am no btrfs expert, and don't know what this means. Next, I tried listing snapshots from the corresponding date:

$ sudo btrfs subvolume list /mnt/timeshift/backup/timeshift-btrfs/snapshots/ | grep 2017-09-05
ID 323 gen 160616 top level 5 path timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home
ID 324 gen 160658 top level 5 path timeshift-btrfs/snapshots/2017-09-05_15-00-01/@
ID 325 gen 160616 top level 323 path timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home/@home
ID 326 gen 160630 top level 324 path timeshift-btrfs/snapshots/2017-09-05_15-00-01/@/@

It seems there are nested snapshots eg. "/@home/@home" where there should only be "/@home". I guess that is what caused the "Directory not empty" error. I delete the nested snapshots manually:

$ sudo btrfs subvolume delete --commit-after '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home/@home'
Delete subvolume (commit): '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home/@home'
$ sudo btrfs subvolume delete --commit-after '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home'
Delete subvolume (commit): '/mnt/timeshift/backup/timeshift-btrfs/snapshots/2017-09-05_15-00-01/@home'

(and same for "/@")

It seems to have worked.

Within Timeshift GUI, the snapshot seems to exist (greyed out still). When I hit "Delete", the snapshot disappears from the list.

I guess this is a success for me, but a cumbersome workaround!

Timeshift seems to create nested snapshots occasionally. When deleting from GUI, the top level snapshot is selected, and so cannot be deleted (due to a sub-snapshot residing within). This is the issue I'm reporting here, as it is making snapshot deletion impossible from within the Timeshift GUI. I don't know if the fix should be in the snapshot creation, or in the snapshot deletion.

Best regards, Mikael

G-M0N3Y-2503 commented 3 years ago

I came across this issue with Manjaro KDE 21.1.5 with brtfs and docker. I was subsequently able to reproduce the same issue in a VM with Manjaro xfce 21.1.5 with btrfs and docker, Here are the steps to reproduce:

  1. sudo pamac install docker
    • didn't include optional extras
  2. sudo timeshift --create --comments "First"
output ``` Using system disk as snapshot device for creating snapshots in BTRFS mode /dev/vda1 is mounted at: /run/timeshift/backup, options: rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ Creating new backup...(BTRFS) Saving to device: /dev/vda1, mounted at path: /run/timeshift/backup Created directory: /run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_14-57-17 Created subvolume snapshot: /run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_14-57-17/@ Created control file: /run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_14-57-17/info.json BTRFS Snapshot saved successfully (0s) Tagged snapshot '2021-10-09_14-57-17': ondemand ------------------------------------------------------------------------------ ```
  1. sudo systemctl start docker.service
  2. sudo docker run -it hello-world
  3. sudo timeshift --list --snapshot-device /dev/vda1
output ``` /dev/vda1 is mounted at: /run/timeshift/backup, options: rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ Device : /dev/vda1 UUID : 6ededd65-0bd1-486a-a890-c5fe8806918d Path : /run/timeshift/backup Mode : BTRFS Status : OK 2 snapshots, 18.8 GB free Num Name Tags Description ------------------------------------------------------------------------------ 0 > 2021-10-09_14-54-32 O {timeshift-autosnap} {created before upgrade} 1 > 2021-10-09_14-57-17 O First ```
  1. sudo btrfs subvolume list /
output ``` ID 257 gen 51 top level 5 path @ ID 258 gen 57 top level 5 path @home ID 259 gen 38 top level 5 path @cache ID 260 gen 54 top level 5 path @log ID 269 gen 35 top level 5 path timeshift-btrfs/snapshots/2021-10-09_14-54-32/@ ID 270 gen 43 top level 5 path timeshift-btrfs/snapshots/2021-10-09_14-57-17/@ ID 271 gen 48 top level 257 path var/lib/docker/btrfs/subvolumes/db90b52273bda561111638c9a673097dec5435374335df5f204d1cc6ac7933f2 ID 272 gen 49 top level 257 path var/lib/docker/btrfs/subvolumes/866dcd1ec2aa942ae33d89db0daf0eeae949226dcecf641e5d7d534a3fd5ee96-init ID 273 gen 49 top level 257 path var/lib/docker/btrfs/subvolumes/866dcd1ec2aa942ae33d89db0daf0eeae949226dcecf641e5d7d534a3fd5ee96 ```
  1. sudo timeshift --restore --snapshot '2021-10-09_14-57-17' --target /dev/sda1
  2. sudo reboot
  3. sudo timeshift --create --comments "Second"
output ``` Using system disk as snapshot device for creating snapshots in BTRFS mode /dev/vda1 is mounted at: /run/timeshift/backup, options: rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ Creating new backup...(BTRFS) Saving to device: /dev/vda1, mounted at path: /run/timeshift/backup Created directory: /run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_15-15-34 Created subvolume snapshot: /run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_15-15-34/@ Created control file: /run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_15-15-34/info.json BTRFS Snapshot saved successfully (0s) Tagged snapshot '2021-10-09_15-15-34': ondemand ------------------------------------------------------------------------------ ```
  1. sudo timeshift --list --snapshot-device /dev/vda1
output ``` /dev/vda1 is mounted at: /run/timeshift/backup, options: rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ Device : /dev/vda1 UUID : 6ededd65-0bd1-486a-a890-c5fe8806918d Path : /run/timeshift/backup Mode : BTRFS Status : OK 4 snapshots, 18.8 GB free Num Name Tags Description ------------------------------------------------------------------------------ 0 > 2021-10-09_14-54-32 O {timeshift-autosnap} {created before upgrade} 1 > 2021-10-09_14-57-17 O First 2 > 2021-10-09_15-11-23 O Before restoring '2021-10-09 14:57:17' 3 > 2021-10-09_15-15-34 O Second ```
  1. sudo timeshift --delete --snapshot '2021-10-09_15-11-23'
output ``` Select backup device: Num Device Size Type Label ------------------------------------------------------------------------------ 0 > /dev/vda1 26.8 GB btrfs Enter device name or number (a=Abort): 0 /dev/vda1 is mounted at: /run/timeshift/backup, options: rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ ------------------------------------------------------------------------------ Removing snapshot: 2021-10-09_15-11-23 Deleting subvolume: @ (Id:257) E: ERROR: Could not destroy subvolume/snapshot: Directory not empty E: Failed to delete snapshot subvolume: '/run/timeshift/backup/timeshift-btrfs/snapshots/2021-10-09_15-11-23/@' E: Failed to remove snapshot: 2021-10-09_15-11-23 ------------------------------------------------------------------------------ ```
  1. sudo btrfs subvolume list /
output ``` ID 257 gen 70 top level 5 path timeshift-btrfs/snapshots/2021-10-09_15-11-23/@ ID 258 gen 88 top level 5 path @home ID 259 gen 73 top level 5 path @cache ID 260 gen 88 top level 5 path @log ID 269 gen 35 top level 5 path timeshift-btrfs/snapshots/2021-10-09_14-54-32/@ ID 270 gen 64 top level 5 path timeshift-btrfs/snapshots/2021-10-09_14-57-17/@ ID 271 gen 48 top level 257 path timeshift-btrfs/snapshots/2021-10-09_15-11-23/@/var/lib/docker/btrfs/subvolumes/db90b52273bda561111638c9a673097dec5435374335df5f204d1cc6ac7933f2 ID 272 gen 49 top level 257 path timeshift-btrfs/snapshots/2021-10-09_15-11-23/@/var/lib/docker/btrfs/subvolumes/866dcd1ec2aa942ae33d89db0daf0eeae949226dcecf641e5d7d534a3fd5ee96-init ID 273 gen 49 top level 257 path timeshift-btrfs/snapshots/2021-10-09_15-11-23/@/var/lib/docker/btrfs/subvolumes/866dcd1ec2aa942ae33d89db0daf0eeae949226dcecf641e5d7d534a3fd5ee96 ID 274 gen 87 top level 5 path @ ID 275 gen 79 top level 5 path timeshift-btrfs/snapshots/2021-10-09_15-15-34/@ ```

Hope this helps track this issue down.

emanuc commented 3 years ago

ID 271 gen 48 top level 257 path var/lib/docker/btrfs/subvolumes/db90b52273bda561111638c9a673097dec5435374335df5f204d1cc6ac7933f2

The problem is that inside the subvolume "@" has nested snapshots [1], to avoid this problem, create a subvolume on the toplevel (ID5).

[1] ID 271 gen 48 top level 257 path timeshift-btrfs/snapshots/2021-10-09_15-11-23/@/var/lib/docker/btrfs/subvolumes/db90b52273bda561111638c9a673097dec5435374335df5f204d1cc6ac7933f2

For more information: https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Layout

teejee2008 commented 3 years ago

One solution is to create a top level subvolume named @docker and mount it at /var/lib/docker using /etc/fstab. By doing this the nested subvolumes created by docker will remain outside of @

marko19914 commented 2 years ago

Hello! Experiencing the same issue on Fedora 36. sudo timeshift --delete --snapshot 2022-07-01_22-49-38

Output

/dev/sda3 is mounted at: /run/timeshift/backup, options: rw,seclabel,relatime,compress=zstd:1,ssd,space_cache=v2,subvolid=5,subvol=/


Removing snapshot: 2022-07-01_22-49-38 Deleting subvolume: @ (Id:257) E: ERROR: Could not destroy subvolume/snapshot: Directory not empty

E: Failed to delete snapshot subvolume: '/run/timeshift/backup/timeshift-btrfs/snapshots/2022-07-01_22-49-38/@' E: Failed to remove snapshot: 2022-07-01_22-49-38

As a workaround managed to remove the snapshot cd /run/timeshift/backup/timeshift-btrfs/snapshots/ sudo rm -rf 2022-07-01_22-49-38/

We'll see what might be the consequences.