Download and Backup Digital Ocean Snapshot Images
NOTE!: I haven’t had time to test going back and restoring. I am hesitant to remove my images from DigitalOcean until I can confirm the backup is working properly. I’ve been holding back on posting this until then, but I’m tired of sitting on this and hope it helps others.
I am not responsible for any data loss or harm you or another may cause to your system or data.
Add an SSH Key to your account
Use PuttyGen to generate a key, save the public and private
Add the key to DO
Create New Droplet
Create a droplet from the snapshot image you want to download
Remember to check the key you created
You may need to choose a larger storage space if you’re going to create a backup locally.
Validate Previous SSH Settings
If you disabled logging in from root, you’ll need to reset the root password from the DO pannel.
Then log in with the DO console and edit the
/etc/ssh/sshd_config
Enable PermitRootLogin yes
Then add this line below
PermitRootLogin without-password
Make sure if you’re white-listing users you either add root or comment the line out
#AllowUsers UserName root
Restart the SSH server with
service ssh restart
Now if you’ve added your SSH key to Digital Ocean and the droplet when you created it you should be able to connect with Putty.
Connecting with Putty
Add IP, Connection > Data > Auto Login Username: root
Add your private key, Connection > SSH > Auth > Private Key File > Browse
Connect, enter your passphrase you created when you generated the SSH Key
You should see something like:
Authenticated with public key "Digitatl-Ocean-rsa-key-#######"
Passphrase for key "Digital-Ocean-rsa-key-#######:"
Optional (Recommended) – Create Serverside Backup
You can choose to zip everything up on the server if you’d like or just copy it all over in the next step
https://help.ubuntu.com/community/DriveImaging You can use the BZ compression if you want, I chose gzip.
at the root with root permissions run
dd if=/dev/vda1 | gzip > backup.gz
vda1 can be found via:
ls /dev/disk/by-label/ -l
http://stackoverflow.com/questions/10555066/watch-file-size-on-linux
You can watch the progress with another terminal and the following command; remove the h if you want to watch the bytes
watch -n 3 “du -h backup.gz”
Exclude or include only specific files:
exclude from file:
https://www.gnu.org/software/tar/manual/html_section/tar_49.html
include from file:
http://stackoverflow.com/questions/8033857/tar-archiving-that-takes-input-from-a-list-of-files
What to include?
This askubuntu has a good answer
http://askubuntu.com/questions/222326/which-folders-to-include-in-backup
List packages:
http://askubuntu.com/a/55906/104223
From Article
/var (except /var/run, /var/cache, /var/tmp)
/srv
/etc
/root
/home
/usr (/usr/local only, nothing else)
You can also install NCDU
https://codyswartz.us/wp/linux/linux-find-out-how-much-each-folder-is-taking-up
and determine which folders are your big hitters for a better idea
Include File
nano my-includes.txt
/usr
/var
/lib
/etc
/root
/home
/srv
/opt
Exclude File
nano my-excludes.txt
/backups
/boot
/run
/var/run
/var/cache
/var/tmp
/var/lib/apt/lists
/lib/modules
/usr/share
/usr/src
/usr/lib
/usr/bin
/usr/sbin
Just configs no executables
/backups
/boot
/run
/var/run
/var/cache
/var/tmp
/var/lib/apt/lists
/bin
/lib
/lib64
/sbin
/usr/share
/usr/src
/usr/lib
/usr/bin
/usr/sbin
Time To Backup
Lets build a big scary backup command!
- https://help.ubuntu.com/community/BackupYourSystem/TAR
- http://stackoverflow.com/questions/8033857/tar-archiving-that-takes-input-from-a-list-of-files
- http://superuser.com/questions/256378/put-date-into-backup-tar-gz-filename
mkdir backups
dpkg --get-selections > app-list.txt
tar -cvpjf /backups/backup-$(date +%Y-%m-%d-%H-%M-%S).tar.bz2 --one-file-system / -X my-excludes.txt -T my-includes.txt --hard-dereference
Windows WinSCP
Copy file from server
Final Steps
Take a deep breath and pull the trigger…
Remove those snapshots from Digital Ocean… Phew