项目作者: jotyGill

项目描述 :
Automated Offline Or Live Backups (Snapshots) Of Digitalocean Droplets
高级语言: Python
项目地址: git://github.com/jotyGill/digitalocean-backup.git
创建时间: 2018-05-15T06:43:33Z
项目社区:https://github.com/jotyGill/digitalocean-backup

开源协议:

下载


dobackup


Downloads


Simple Automated offline snapshots of digitalocean droplets utilising python-digitalocean.
The script safely shutdowns a given droplet or all droplets with a give tag then performs snapshots of them, Then
it turns them back on. Every step is logged as well as displayed in the console output.
The script is designed to be used as a cron job as well. If any error occurs the script logs it then exits with
exit code of 1. Very useful feature to ensure that the backups are successfully completed. I use it to delete older
backups only if new one is successful and to use a ‘healthchecks’ service to get notified if a backup failed.
(see cron examples)

dobackup

Installation

Install as a user without sudo. This installs it in ~/.local/bin/ make sure this path is in your $PATH.

  1. python3 -m pip install --user -U dobackup

If not found, add the following to your .bashrc or .zshrc

  1. # Add to PATH to Install and run programs with "pip install --user"
  2. export PATH=$PATH:~/.local/bin

Usage

Initialise

Store the api access token in .token file by running ‘—init’ and providing the token string.

  1. dobackup --init
  2. # Paste the digitalocean token string, press enter
  3. # If you have multiple accounts, paste each- press enter, so on
  4. # When done, just press enter to submit an empty string
  5. # The sequence of these tokens (0,1,2) will be later used to "use" the tokens

To use one of the stored tokens, specify it’s index after “dobackup “,

  1. dobackup 0 # 0 is implicit
  2. dobackup 1 # will use token 1
  3. dobackup 2 # will use token 2

Display Information

Display Information about droplets and snapshots using —list commands.
Examples

  1. dobackup --list-droplets
  2. dobackup --list-snaps
  3. dobackup --list-backups # snaps created using this tool
  4. dobakcup --list-older_than 7 # lists backup taken by dobackup that are older than 7 days
  5. dobackup --list-tags
  6. dobackup --list-tagged # list tagged servers with the tag 'dobackup'

Use Tags (optional)

Use tags to backup multiple servers at ones. Use existing tags or create new.
Default tag is ‘dobackup’ .
To tag a server with a ‘dobakup’ tag.

  1. dobackup --tag-server ubuntu-18-04 # '--tag-name dobackup' is implicit

To tag a server with ‘web-servers’ tag.

  1. dobackup --tag-server ubuntu-18-04 --tag-name web-servers

NOTE: In 2.0, —‘tag-name’— is appended to the backup name, instead of hardcoded str ‘—dobackup—‘.
The default value of tag_name is still ‘dobackup’. Now we can use —tag-name along with —list-backups, —list-older-than,
—delete-older-than. Now we can keep the backups of droplets with lets say ‘tag1’ for 5 days and ‘tag2’ for 10 days.
example command. “—delete-older-than 5 —tag-name ‘tag1’” , “—delete-older-than 10 —tag-name ‘tag2’”

Perform Backups

To backup a server using it’s name or id.

  1. dobackup --backup ubuntu-18-04
  2. dobackup --backup 1929129
  3. dobackup --live-backup ubuntu-18-04 # live backup, backup without shutting down the vm
  4. dobackup --backup ubuntu-18-04 --keep # this won't be deleted with '--delete-older-than'

To backup all servers that have a given tag.

  1. dobackup --backup-all # --tag-name dobackup is implicit
  2. dobackup --backup-all --tag-name web-servers

To set a cron job, to backup all ‘tagged’ servers and auto delete old backups, if backups were successful

  1. 0 1 * * * ~/.local/bin/dobackup --backup-all && ~/.local/bin/dobackup --delete-older-than 7

Using amazing utility healthchecks. to get notified if an error occurred during the process.

  1. 0 1 * * * ~/.local/bin/dobackup --backup-all && ~/.local/bin/dobackup --delete-older-than 7 && wget -O/dev/null https://hc-ping.com/your-string

Perform Restore

To restore a server using it’s name or id and snapshot’s name or id

  1. dobackup --restore-droplet ubuntu-18-04 --restore-to "ubuntu-18-04--dobackup--2018-06-01 14:36:07"

Delete Old Backups

To delete a specific snapshot.

  1. dobackup --delete-snap "ubuntu-1gb-sgp1-01--dobackup--2018-05-31 17:43:11" # put snap name or id
  2. dobackup --delete-snap "111111111,222222222,3333333333" # comma seperated multiple ids or names

To delete all old backups taken with dobackup.

  1. # delete snapshots older than 14 days with '--dobackup--' in their names
  2. # WILL NOT delete snapshots with '--dobackup-keep--' in their names
  3. dobackup --delete-older-than 14

Options

  1. usage: dobackup [-h] [-v] [--init] [-l] [--list-backups] [-s] [--list-tagged]
  2. [--list-tags] [--list-older-than LIST_OLDER_THAN]
  3. [--backup BACKUP] [--backup-all] [--live-backup LIVE_BACKUP]
  4. [--live-backup-all] [--tag-droplet TAG_DROPLET]
  5. [--untag-droplet UNTAG_DROPLET] [--tag-name TAG_NAME]
  6. [--delete-older-than DELETE_OLDER_THAN]
  7. [--delete-snap DELETE_SNAP] [--shutdown SHUTDOWN]
  8. [--powerup POWERUP] [--restore-droplet RESTORE_DROP]
  9. [--restore-to RESTORE_TO] [--keep]
  10. [token_id]
  11. Automated Offline Or Live Snapshots Of Digitalocean Droplets
  12. positional arguments:
  13. token_id Specify token number to be used, default=0, supply
  14. only if you have multiple Digitalocean accounts
  15. optional arguments:
  16. -h, --help show this help message and exit
  17. -v, -V, --version show programs version number and exit
  18. --init Save token to .token file
  19. --tag-name TAG_NAME To be used with "--list-tags", "--tag-droplet" and "--
  20. backup-all", default value is "dobackup"
  21. --keep To keep backups for long term. "--delete-older-than"
  22. wont delete these. To be used with "--backup","--
  23. backup-all"
  24. Informational Args:
  25. Arguments That Display Information
  26. -l, --list-droplets List all droplets
  27. --list-backups List all snapshots with "dobackup" in their name
  28. -s, --list-snaps List all snapshots
  29. --list-tagged List droplets using "--tag-name"
  30. --list-tags List all used tags
  31. --list-older-than LIST_OLDER_THAN
  32. List snaps older than, in days
  33. Backup Args:
  34. Arguments That Backup Or Restore Droplets
  35. --backup BACKUP Shutdown, Backup (snapshot), Then Restart the droplet
  36. with given name or id
  37. --backup-all Shutdown, Backup (snapshot), Then Restart all droplets
  38. with the given "--tag-name"
  39. --live-backup LIVE_BACKUP
  40. Backup (snapshot), the droplet with given name or id,
  41. without shutting it down
  42. --live-backup-all Backup (snapshot), all droplets with the given "--tag-
  43. name", without shutting them down
  44. --restore-droplet RESTORE_DROP
  45. Restore, the droplet with given name or id
  46. --restore-to RESTORE_TO
  47. Snapshot id or name, to restore the droplet to
  48. Action Args:
  49. Arguments That Perform Actions
  50. --tag-droplet TAG_DROPLET
  51. Add tag to the provided droplet name or id
  52. --untag-droplet UNTAG_DROPLET
  53. Remove tag from the provided droplet name or id
  54. --delete-older-than DELETE_OLDER_THAN
  55. Delete backups older than, in days
  56. --delete-snap DELETE_SNAP
  57. Snapshot(s) by name or id. e.g --delete-snap 111111 or
  58. --delete-snap '111111,222222,333333'
  59. --shutdown SHUTDOWN Shutdown, the droplet with given name or id
  60. --powerup POWERUP Powerup, the droplet with given name or id