[How-to] recover data in BTRFS on Asustor NAS crashed

Share your awesome tips and tricks here.

Moderator: Lillian.W@AST

Post Reply
User avatar
father.mande
Posts: 1809
youtube meble na wymiar Warszawa
Joined: Sat Sep 12, 2015 2:55 am
Location: La Rochelle (France)

[How-to] recover data in BTRFS on Asustor NAS crashed

Post by father.mande »

Hi,
===== based on real case, after the break of my AS5002T

This small How-to is to explain shortly, how it's possible to recover your data (and App if needed) on a NAS using BTRFS ... ex. after a stop of your NAS but with disk seeming to be O.K.

1) remember structure (here for the example : a x86_64 NAS with a single disk ... EVEN configured by NAS as a Raid 1 with only one member)
DATA are in partition 4 of the disk (configured as RAID 1 even single)
BTRFS mount is done using 3 sub-volume and not a unique one
... mount 1 : is mounted on /volume1 with : subvolid=256 and subvol=/base
... mount 2 : is mounted on /volume1/.@iscsi : subvolid=258,subvol=/.iscsi ... reserved for providing iscsi
... mount 3 : is mounted as /volume1/.@plugins : subvolid=259,subvol=/.@plugins ... it's on live NAS : /usr/local/ ... AppCentral for ex.
... other mount are for visibility of folder in /volume1 from other mountpoint (ex. /home and shared resources ... SO NOT necessary for recovering ...

Code: Select all

root@AS5002TAPHIL:/volume1/.@root # btrfs subvolume list /volume1
ID 256 gen 1117 top level 5 path base
ID 258 gen 801 top level 5 path .iscsi
ID 259 gen 1117 top level 5 path .@plugins
root@AS5002TAPHIL:/volume1/.@root #
2) prerequisite :
... a running Lunx system with Raid tools and BTRFS support
... for my example it's a Vmware Virtual Machine using Ubuntu focal (20.04) but real system or any other virtual machine can be used
... ... the only point is : to be able to attach the external disk(s) using for ex. USB3 box to the V.M.
... ... on my PC it's an USB3 startech box
when disk is connected device /dev/sdb[1,2,3,4] are created and sdc etc. etc. for each disk (starting can sdc sdd or whatever depending of your VM configuration (mine use only one disk for Ubuntu)

... now it's time to reassemble the Raid (remember the good order of disks (specially for Raid5 or 6)
... ... command is like : (as root) mdadm --assemble /dev/md1 /dev/sdb4
... ... ignore error like device busy ... just check that /dev/md1 is created : ls -ali /dev/md1

... now it's time to mount btrfs base (volume1 without .@plugins and .@iscsi)
... create the mount point
... ... command like : mkdir /mnt/volume1 ; chmod 777 /mnt/volume1 or what you want (adapt next lines)
... mount BTRFS base :
... ... command like : mount -t btrfs /dev/md1 /mnt/volume1/

NOW ALL your data (in shared resources) are available (ex. here after my structure)

Code: Select all

root@philippe-2004:~# mount -t btrfs /dev/md1 /mnt/volume1/
root@philippe-2004:~# ll /mnt/volume1/
total 4
drwxr-xr-x 1 root             root              418 juin  10 08:41  ./
drwxr-xr-x 4 root             root             4096 juin  10 15:01  ../
drwxr-xr-x 1 root             root              194 juin  10 08:41 '.@CNID'/
drwxr-xr-x 1 root             root               20 déc.  30  2019 '.@content'/
drwxr-xr-x 1 root             root              146 juin  10 08:41 '.@extthumbnail'/
drwxr-xr-x 1 root             root               10 févr. 13  2019 '.@ezsync'/
drwxr-xr-x 1 root             root               54 juin  29  2020  home/
drwxr-xr-x 1 root             root                0 janv. 26  2019 '.@iscsi'/
drwsrwsrwt 1 root             root                0 janv. 28  2019  iscsi/
drwxr--r-- 1 root             root               44 juin   3 18:01 '.@login_style'/
drwxrwxrwx 1 systemd-coredump systemd-coredump  150 mars  12 17:46  Media/
drwxrwxrwx 1 systemd-coredump systemd-coredump   32 déc.  27  2018  Music/
drwxrwxrwx 1 systemd-coredump systemd-coredump    0 juin   6  2020 'mytest & value'/
drwxrwxrwx 1 systemd-coredump systemd-coredump   62 sept.  5  2019 'myvideo & sound'/
drwxrwxrwx 1 systemd-coredump systemd-coredump    0 janv. 21  2020  Octoprint/
drwxrwxrwx 1 systemd-coredump systemd-coredump   14 janv. 26  2019  Plex/
drwxr-xr-x 1 root             root                0 janv. 26  2019 '.@plugins'/
drwxrwxrwx 1 root             systemd-coredump 2856 juin   2 17:32  Public/
drwx------ 1 root             root              564 juin   5 18:59 '.@root'/
drwxr-x--- 1 systemd-coredump systemd-coredump    0 janv. 26  2019 '.@snapshots'/
drwxrwxrwx 1 systemd-coredump systemd-coredump   40 avril 15  2020  Syncthing/
drwxr-xr-x 1 root             root               40 juin  10 08:41 '.@system'/
drwxrwxrwx 1 systemd-coredump systemd-coredump  260 avril 23 17:27  test/
drwxr-xr-x 1 root             root                8 juin   4 16:59 '.@thumbnail'/
drwxrwxrwx 1 root             root               18 juin  10 08:47 '.@tmp'/
drwxrwxrwx 1 root             root                0 juin  10 08:41 '.@trashcan'/
drwx------ 1 root             root                0 juin   3 11:34 '.@uploads'/
drwxrwxrwx 1 systemd-coredump systemd-coredump  160 juin   8 17:38  Web/
User name and group are incorrect ... but not really a problem
.@plugins is empty (sub-volume not mounted)

Now if you want to get AppCentral (for ex. to get some config file or data put in APKG folder)
... this part is in the sub-volume 256
... mount it
... ... command like : mount -t btrfs -o subvolid=259,subvol=/.@plugins /dev/md1 /mnt/volume1/.@plugins/

Code: Select all

root@philippe-2004:~# ll /mnt/volume1/.@plugins/
total 0
drwxr-xr-x 1 root root   0 janv. 26  2019 ./
drwxr-xr-x 1 root root 418 juin  10 08:41 ../
root@philippe-2004:~# mount -t btrfs -o subvolid=259,subvol=/.@plugins /dev/md1 /mnt/volume1/.@plugins/
root@philippe-2004:~# ll /mnt/volume1/.@plugins/
total 4
drwxr-xr-x 1 root root  130 mars  15 09:15 ./
drwxr-xr-x 1 root root  418 juin  10 08:41 ../
drwxr-xr-x 1 root root  684 juin  10 09:06 AppCentral/
drwxr-xr-x 1 root root  498 juin  10 10:14 bin/
drwxr-xr-x 1 root root   14 janv. 26  2019 cache/
drwxr-xr-x 1 root root   24 janv. 26  2019 etc/
drwxr-xr-x 1 root root  516 juin  10 09:06 lib/
drwxr-xr-x 1 root root    0 déc.  25  2018 lib64/
drwsrwsrwt 1 root root  210 juin   6 18:19 .myHD/
drwsrwsrwt 1 root root  194 mars  12 19:15 .myHD_prev/
drwxr-xr-x 1 root root   36 juin  10 10:14 sbin/
drwxr-xr-x 1 root root    0 déc.  25  2018 share/
drwxr-xr-x 1 root root 1992 juin  10 09:06 tmp/
drwxr-xr-x 1 root root  420 juin  10 09:06 webman/
lrwxr-xr-x 1 root root   12 janv. 26  2019 www -> /volume1/Web
root@philippe-2004:~# 
Final result in term of mount point :

Code: Select all

root@philippe-2004:~# mount | grep btrfs
/dev/md1 on /mnt/volume1 type btrfs (rw,relatime,space_cache,subvolid=257,subvol=/base)
/dev/md1 on /mnt/volume1/.@plugins type btrfs (rw,relatime,space_cache,subvolid=259,subvol=/.@plugins)
root@philippe-2004:~# 
Tips :
You can use /volume1 as mount point if you want to keep the NAS structure
Use tools like tar, etc. for backup that are able to preserve User ID (and not name) and preserve Symlink and access permissions.
Please start from a clean Ubuntu (ex. from a last snapshot in Vmware) and be sure to umount all BEFORE suspending the VM (stooping it don't have this problem)
You can also if NAS don't shutdown safely ... you can after reassemble ... check bad blocks and after mount check file system ...

NOT SURE ... BUT hope that this can help you in some cases ...
Philippe.
AS6602T / AS5202T /AS5002T / AS1002T / FS6706T
Post Reply

Return to “Tips & Tricks”