Skip to content

Instantly share code, notes, and snippets.

@Jbithell
Last active July 9, 2016 09:54
Show Gist options
  • Save Jbithell/398e4cd1662abe9fa936750338962763 to your computer and use it in GitHub Desktop.
Save Jbithell/398e4cd1662abe9fa936750338962763 to your computer and use it in GitHub Desktop.
A system for snapshotting a droplet itself on DO
#!/bin/bash
#THIS SCRIPT MUST BE RUN AS ROOT
token=""
dropletid=""
dumpmysqlpass="password" #Set this to what you set in the setup!
cd /
mysqldump -u dump -p $dumpmysqlpass --all-databases > /databasebackup.sql #Dump the MySQL
doctl compute droplet-action snapshot $dropletid --wait --snapshot-name "Regular Auto Snapshot whilst running." -t $token #Run the snapshot
rm -r /databasebackup.sql #We no longer need that MySQL dump
cd /
@Jbithell
Copy link
Author

Jbithell commented Jul 9, 2016

Setup

MySQL

CREATE USER 'dump'@'localhost' IDENTIFIED BY 'password';
GRANT USAGE ON *.* TO 'dump'@'localhost';
GRANT SELECT, LOCK TABLES ON `mysql`.* TO 'dump'@'localhost';
GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON `myschema`.* TO 'dump'@'localhost';
FLUSH PRIVILEGES;

Install Doctl

cd ~
wget -qO- https://github.com/digitalocean/doctl/releases/download/v1.3.0/doctl-1.3.0-linux-amd64.tar.gz  | tar xz
sudo mv ./doctl /usr/local/bin

Crontab

Pop this script in your crontab - though remembering it must be run as root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment