File system corruption on your server can happen when software or hardware malfunctions or when your server is abruptly powered off. The success of your recovery operations comes down to a number of factors, such as how quickly the filesystem noticed the corruption, how widespread the issue was, and what files were affected.
The best way to prevent data loss in these situations is with good backups. Implementing a reliable offsite backup solution and thoroughly testing it on a regular basis is the only way to guarantee the integrity of your data.
However, you can also use DigitalOcean’s recovery ISO to run
fsck, a filesystem check program. This recovery option can be useful, but it comes with risks and isn’t guaranteed to work, so consider it a last resort method of data recovery.
First, power off your Droplet in the safest way available to you. If you have access to the command line, you can use the
If you do not have access to the command line, you can power off the Droplet using the toggle on the Droplet’s page in your control panel.
We recommend taking a snapshot of your server before attempting to recover using
fsck. If the recovery causes data loss, you can restore from the snapshot and try again or use a different method.
In the control panel, click Recovery on the left, then click the Boot from Recovery ISO box:
Next, toggle the power button to power your Droplet back on. When it’s on, access your Droplet by clicking on Access to the left, then clicking the Launch Console button. You’ll see a menu like this:
This droplet is booted to the DigitalOcean recovery environment. When you are finished, you may set your Droplet to boot from the local disk again via the DigitalOcean control panel. This rescue environment is based on Ubuntu 18.04. * Network access and SSH have been enabled automatically * * SSH Host keys will NOT match while using this rescue system * Root Password has randomly been set to: exam-ple0-1234-5678 Your are strongly encouraged to use SSH keys. To import your SSH public keys: From Github: ssh-import-id gh:<Github user name> From Launchpad.net: ssh-import-id lp:<launchpad user name> -------------------------------------------------------------------- 1. Mount your Disk Image [Not Mounted] 2. Check Filesystem 3. Reset Droplet Root Password 4. Configure Keyboard 5. Attempt to 'chroot' into installed system 6. Interactive Shell [/bin/bash] Choose (1-6) and press Enter to continue.
The recovery ISO provides a number of options.
You can SSH to the Droplet while it’s in recovery using the temporary password shown on the recovery menu in the console. If you use SSH to connect, you’ll need to use a screen, tmux, or byobu session.
Your SSH keys will not work while the Droplet is in recovery, but you can import them from GitHub if you have them there by following the instructions in the recovery menu. The Droplet’s host key will also not match, so you may have to delete it from the
~/.ssh/known_hosts file on your local computer to connect via SSH.
fsck can occasionally cause data corruption on active disks, so only attempt this on an unmounted file system. To run
2 from the menu and press
ENTER. The recovery environment will detect your disk image and attempt to run an fsck on it. It will report any errors and bring any issues to your attention.
This Linux environment is running from the ISO image, not from your Droplet, so you will have to mount the filesystem into your environment in order to access your files. To do so, select
1 at the recovery menu and press
ENTER. Your disk image will be detected and mounted under
/mnt in the recovery environment.
Next, you will need to enter an interactive bash shell environment by selecting
6 from the menu and pressing
ENTER. If you previously ran a filesystem check from the recovery ISO, you can now check for any partially recovered files in the
Move to the
cd /mnt ls
You should see your Droplet’s filesystem:
bin/ etc/ lib/ media/ proc/ sbin/ sys/ var/ boot/ home/ lib64/ mnt/ root/ selinux/ tmp/ vmlinuz@ dev/ initrd.img@ lost+found/ opt/ run/ srv/ usr/
From here, you can check the
lost+found directory for partially recovered files:
cd lost+found ls
Your options at this point depend on how successful your recovery operations were. If the
lost+found directory has files that were recovered by fsck, you can attempt to move them back into place on the system. This may help your system boot and function correctly if they were important files. If the recovery went well and the Droplet itself is salvageable, you can power off from the command line again:
Then, back in the control panel, click Recovery and then choose the radio button for Boot from Hard Drive. When you power the Droplet back on, it will attempt to boot from its own disk.
If the files in
lost+found are unrecoverable, or if you do not want to try to restore the Droplet and only want to save some data, you can offload your files onto a remote machine (like another Droplet or another physical machine). You can use SFTP from the command line or with an SFTP client like Filezilla. Make sure to use the temporary password in the recovery menu when you set up the connection.
You can also attempt to
chroot into the filesystem if you wish to try more advanced recovery steps. For example, this may allow you to start MySQL so you can attempt to export your databases. However, this may not always work, depending upon the state of the filesystem.
Simple recovery using automated tools is often a function of luck.
fsck recovery can help get your server back or at least get your files, but keeping good backups is the most important step you can take to prevent data loss.