# Synology Recover Data

<a href="https://github.com/007revad/Synology_Recover_Data/releases"><img src="https://img.shields.io/github/release/007revad/Synology_Recover_Data.svg"></a>
[![Github Releases](https://img.shields.io/github/downloads/007revad/Synology_Recover_Data/total.svg)](https://github.com/007revad/Synology_Recover_Data/releases)
![Badge](https://hitscounter.dev/api/hit?url=https%3A%2F%2Fgithub.com%2F007revad%2FSynology_Recover_Data&label=Visitors&icon=github&color=%23198754&message=&style=flat&tz=Australia%2FSydney)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/007revad)
[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/007revad)
<!-- [![committers.top badge](https://user-badge.committers.top/australia/007revad.svg)](https://user-badge.committers.top/australia/007revad) -->

### Description

A script to make it easy to recover your data from your Synology's drives using a computer.

Now supports encrypted volumes.


### Confirmed working on

<details>
  <summary>Click here to see the list</summary>

| Drive source | DSM version    | Btrfs/Ext | Storage Pool type | RAID   | Encrypted | Notes           |
|--------------|----------------|-----------|-------------------|--------|-----------|-----------------|
| DS925+       | 7.3.2 Update 3 | Btrfs     | Multiple Volume   | SHR    | no        | 3 drives        |
| DS916+       | 7.2.1 Update 9 | Btrfs     | Single Volume     | RAID 6 | no        | 4 drives        |
| DS720+       | 7.2.1 Update 4 | Btrfs     | Multiple Volume   | SHR    | Volume    | Single drive    |
| DS720+       | 7.2.1 Update 4 | Btrfs     | Multiple Volume   | SHR    | no        | Single drive    |
| DS1812+      | 6.2.4 Update 7 | Btrfs     | Multiple Volume   | SHR    | no        | Single drive    |
| DS1812+      | 6.2.4 Update 7 | Btrfs     | Single Volume     | Basic  | no        | **Failed, faulty HDD** |

</details>


### What does the script do?

The script automatically does steps 4 to 15 from this web page: <br>
https://kb.synology.com/en-id/DSM/tutorial/How_can_I_recover_data_from_my_DiskStation_using_a_PC

So you need to do steps 1 to 3 from that web page.

The same environment rules as on Synology's web page apply:

**Applicable to:**
- DSM version 6.2.x and above
- Volumes using the Btrfs or ext4 file systems
- Encrypted volumes using the Btrfs or ext4 file systems
- Ubuntu 19.10 (Eoan Ermine) only (Synology's recommended 18.04 has a bug with persistent partition)

> **NOTE** <br>
> Ubuntu 18.04 no longer works. Ubuntu deleted it's package archive. <br>
> Ubuntu 20 and 22 do NOT work. Their newer kernel version does NOT support DSM's superblock location. <br>

**Not applicable to:**
- Volumes using read-write SSD cache

**Currently the script does NOT support:**
- Encrypted shared folders

At the moment the script only supports mounting 1 volume at a time. You'd need to run the script again to mount a 2nd volume.


### Setup to recover data using a PC

1. Make sure your PC has sufficient drive slots for drive installation (you can use a USB dock).
2. Remove the drives from your Synology NAS and install them in your PC or USB dock. For RAID or SHR configurations, you must install all the drives (excluding hot spare drives) in your PC at the same time.
3. Download the **Desktop image** for [Ubuntu version 19.10 Eoan Ermine](https://old-releases.ubuntu.com/releases/19.10/)
   - Synology's recommended 18.04 has a bug with persistent partition so any changes you make in Ubuntu will be lost when you shut down Ubuntu.
   - Newer Ubuntu versions like 20.04.6 LTS and 22.04.4 LTS require an 8GB USB drive and install an mdadm version that won't work with Synology's superblock location and a kernel that prevents mounting Synology's btrfs volumes.
   - A Synology compatible btrfs driver is required for mounting btrfs volumes. See step 7, below.
4. You'll need a 4GB or larger USB drive.
5. Prepare a Ubuntu environment by following the instructions in [this tutorial](https://ubuntu.com/tutorials/create-a-usb-stick-on-windows) with 2 exceptions:
    - Select your downloaded Ubuntu 19.10 iso file.
    - Set Persistent partition size in [Rufus](https://rufus.ie/en/) to greater than 0 so any changes you make in Ubuntu are saved to the USB drive.
    <p align="left"> &nbsp; &nbsp;<img src="/images/rufus.png"></p>
6. If the drives contain an encrypted volume, or volumes:
    - Find your [NASNAME]_volume#.rkey for each encrypted volume. e.g. MYNAS_volume1.rkey, DISKSTATION_volume1.rkey or RACKSTATION_volume1.rkey etc.
    - Copy the *.rkey file or files to a USB drive or network share.
7. Once Rufus has finished creating the boot drive you need to run the PowerShell script. 
    - A Synology compatible btrfs driver is required to mount Synology btrfs volumes, and the **setup_ubuntu_usb.ps1** script adds it to your Ubuntu 19.10 USB drive.
    - Download the latest [Synology_Recover_Data_script zip file](https://github.com/007revad/Synology_Recover_Data/releases).
    - Right-click the downloaded Synology_Recover_Data_script zip file, select Properties, check Unblock, click OK, then extract.
    - Right-click on **setup_ubuntu_usb.ps1** and select **Run with PowerShell**.
    - Enter your USB drive's drive letter when asked.
    <p align="left"> &nbsp; &nbsp;<img src="/images/powershell.png"></p>
8. You can now reboot the computer, [enter the BIOS](https://www.tomshardware.com/reviews/bios-keys-to-access-your-firmware,5732.html) and set it to boot from the USB drive, and boot into Ubuntu.
    - I highly recommend unplugging the SATA cables from the PC's drives, while the computer is turned off, so you don't accidentally install Ubuntu on them.
9. **IMPORTANT!** When you see the GRUB boot menu select "**Try Ubuntu without installing**".

### Extra steps if the volume is encrypted

After booting into Ubuntu:
1. Plug in the USB drive containing the *.rkey file or files, or browse to the network share where your *.rkey file or files are located.
2. Copy the *.rkey file or files to Home.

### Setup in Ubuntu - only needed for v2.0.16 and older

<details>
  <summary>Click here to see the steps</summary>

1. Open Firefox from the tool bar and go to [https://github.com/007revad/Synology_Recover_Data](https://github.com/007revad/Synology_Recover_Data) or https://tinyurl.com/synorecover and download the latest release's [zip file](https://github.com/007revad/Synology_Recover_Data/releases).
    - Or download the latest script directly  https://github.com/007revad/Synology_Recover_Data/releases/latest/download/Synology_Recover_Data.zip 
2. Open Files from the tool bar and click on Downloads, right-click on the zip file and select Extract.
3. Right-click on the syno_restore_data.sh file and select Properties.
    - Click Permissions.
    - Tick Allow executing file as program.
    <p align="left"> &nbsp; <img src="/images/script-permissions-2.png"></p>
4. Copy syno_recover_data.sh up 1 level to home.
    <p align="left"> &nbsp; <img src="/images/home.png"></p>
5. Click on the Show Applications icon on the bottom left of the desktop.
6. Type terminal in the search bar.
7. Right-click on Terminal and click on Save to favorites.
8. Press Esc twice to return to the desktop.

</details>


### Running the script

1. Open Terminal from the tool bar.
2. Type `sudo bash /cdrom/syno_recover_data.sh` and press enter.
    <p align="left"> &nbsp; <img src="/images/run-script-new.png"></p>

**Note:** For v2.0.16 and older:
Type `sudo -i /home/ubuntu/syno_recover_data.sh` and press enter.
 

### Accessing your data

There are 2 ways you can access you data:

- Accessing your volume from the Home folder
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/volume_in_home-2.png"></p>

- Accessing your volume from Media on the tool bar
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/volume_in_media-4.png"></p>

<br>


---
### Screenshots

<p align="left">DSM 7 with 2 storage pools and volumes</p>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/image-volume_2-2.png"></p>

<br>

<p align="left">DSM 7 SHR single volume</p>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/image-vg1000-2.png"></p>

<br>

<p align="left">DSM 6 Classic RAID single volume</p>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/image-md-2.png"></p>

<br>

<p align="left">DSM 7 Encrypted volume</p>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/image-encrypted-volume-2.png"></p>

<br>

<p align="left">v2.0.15 compiling compatbile mdadm version from source</p>
<p align="left"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="/images/v2.0.15.png"></p>

