Package: dobackup
dobackupSimple Automated offline snapshots of digitalocean droplets utilising [python-digitalocean](https://github.com/koalalorenzo/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)InstallationInstall as a user without sudo. This installs it in ~/.local/bin/ make sure this path is in your $PATH.python3-mpipinstall--user-UdobackupIf not found, add the following to your .bashrc or .zshrc# Add to PATH to Install and run programs with "pip install --user"exportPATH=$PATH:~/.local/binUsageInitialiseStore the api access token in .token file by running '--init' and providing the token string.dobackup--init# Paste the digitalocean token string, press enter# If you have multiple accounts, paste each- press enter, so on# When done, just press enter to submit an empty string# The sequence of these tokens (0,1,2) will be later used to "use" the tokensTo use one of the stored tokens, specify it's index after "dobackup ",dobackup0# 0 is implicitdobackup1# will use token 1dobackup2# will use token 2Display InformationDisplay Information about droplets and snapshots using --list commands.
Examplesdobackup--list-droplets
dobackup--list-snaps
dobackup--list-backups# snaps created using this tooldobakcup--list-older_than7# lists backup taken by dobackup that are older than 7 daysdobackup--list-tags
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.dobackup--tag-serverubuntu-18-04# '--tag-name dobackup' is implicitTo tag a server with 'web-servers' tag.dobackup--tag-serverubuntu-18-04--tag-nameweb-serversNOTE: 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 BackupsTo backup a server using it's name or id.dobackup--backupubuntu-18-04
dobackup--backup1929129dobackup--live-backupubuntu-18-04# live backup, backup without shutting down the vmdobackup--backupubuntu-18-04--keep# this won't be deleted with '--delete-older-than'To backup all servers that have a given tag.dobackup--backup-all# --tag-name dobackup    is implicitdobackup--backup-all--tag-nameweb-serversTo set a cron job, to backup all 'tagged' servers and auto delete old backups, if backups were successful01***~/.local/bin/dobackup--backup-all&&~/.local/bin/dobackup--delete-older-than7Using amazing utilityhealthchecks. to get notified if an error occurred during the process.01***~/.local/bin/dobackup--backup-all&&~/.local/bin/dobackup--delete-older-than7&&wget-O/dev/nullhttps://hc-ping.com/your-stringPerform RestoreTo restore a server using it's name or id and snapshot's name or iddobackup--restore-dropletubuntu-18-04--restore-to"ubuntu-18-04--dobackup--2018-06-01 14:36:07"Delete Old BackupsTo delete a specific snapshot.dobackup--delete-snap"ubuntu-1gb-sgp1-01--dobackup--2018-05-31 17:43:11"# put snap name or iddobackup--delete-snap"111111111,222222222,3333333333"# comma seperated multiple ids or namesTo delete all old backups taken with dobackup.# delete snapshots older than 14 days with '--dobackup--' in their names# WILL NOT delete snapshots with '--dobackup-keep--' in their namesdobackup--delete-older-than14Optionsusage:dobackup[-h][-v][--init][-l][--list-backups][-s][--list-tagged][--list-tags][--list-older-thanLIST_OLDER_THAN][--backupBACKUP][--backup-all][--live-backupLIVE_BACKUP][--live-backup-all][--tag-dropletTAG_DROPLET][--untag-dropletUNTAG_DROPLET][--tag-nameTAG_NAME][--delete-older-thanDELETE_OLDER_THAN][--delete-snapDELETE_SNAP][--shutdownSHUTDOWN][--powerupPOWERUP][--restore-dropletRESTORE_DROP][--restore-toRESTORE_TO][--keep][token_id]AutomatedOfflineOrLiveSnapshotsOfDigitaloceanDroplets

positionalarguments:token_idSpecifytokennumbertobeused,default=0,supplyonlyifyouhavemultipleDigitaloceanaccounts

optionalarguments:-h,--helpshowthishelpmessageandexit-v,-V,--versionshowprogramsversionnumberandexit--initSavetokento.tokenfile--tag-nameTAG_NAMETobeusedwith"--list-tags","--tag-droplet"and"--backup-all",defaultvalueis"dobackup"--keepTokeepbackupsforlongterm."--delete-older-than"wontdeletethese.Tobeusedwith"--backup","--backup-all"InformationalArgs:ArgumentsThatDisplayInformation-l,--list-dropletsListalldroplets--list-backupsListallsnapshotswith"dobackup"intheirname-s,--list-snapsListallsnapshots--list-taggedListdropletsusing"--tag-name"--list-tagsListallusedtags--list-older-thanLIST_OLDER_THANListsnapsolderthan,indays

BackupArgs:ArgumentsThatBackupOrRestoreDroplets--backupBACKUPShutdown,Backup(snapshot),ThenRestartthedropletwithgivennameorid--backup-allShutdown,Backup(snapshot),ThenRestartalldropletswiththegiven"--tag-name"--live-backupLIVE_BACKUPBackup(snapshot),thedropletwithgivennameorid,withoutshuttingitdown--live-backup-allBackup(snapshot),alldropletswiththegiven"--tag-name",withoutshuttingthemdown--restore-dropletRESTORE_DROPRestore,thedropletwithgivennameorid--restore-toRESTORE_TOSnapshotidorname,torestorethedropletto

ActionArgs:ArgumentsThatPerformActions--tag-dropletTAG_DROPLETAddtagtotheprovideddropletnameorid--untag-dropletUNTAG_DROPLETRemovetagfromtheprovideddropletnameorid--delete-older-thanDELETE_OLDER_THANDeletebackupsolderthan,indays--delete-snapDELETE_SNAPSnapshot(s)bynameorid.e.g--delete-snap111111or--delete-snap'111111,222222,333333'--shutdownSHUTDOWNShutdown,thedropletwithgivennameorid--powerupPOWERUPPowerup,thedropletwithgivennameorid