CloudWays - bash script to download local backups for all applications on a server
bin/bash|
|# CloudWays - Download local backups for all applications|
|# 
|# * Local backups must be enabled and available. See httpssupport.cloudways.com/how-to-download-a-full-backup/|
|# * Add your machine's SSH key to your server so this script needs no input.|
|# * Backups will be saved inside a new folder with today's date within your nominated backup directory. (This might not be the date the backup was taken
|# * Only tested on Digital Ocean VPS so far.|
|# Configuration|
|username='YOUR_MASTER_CREDENTIALS_USERNAME'|
|serverIp='YOUR_SERVER_IP'|
|backupDir='LOCAL_BACKUP_DIRECTORY_PATH' # Example: CloudWays/Backups'|
|# Get the application IDs to backup|
|echo "Retrieving application IDs
|appsssh $username@$serverIp ls /home/master/applications
|appCountapps
|if ! appCount > 0)) ; then|
|echo "😱 Download failed. Could not retrieve application IDs
|exit|
|fi|
|echo "$appCount applications found
|# Create and switch to the backup directory|
|dirbackupDirdate F
|if ! mkdir "$dir" ; then|
|echo "😱 Download failed. Could not create backup directory
|exit|
|fi|
|cd "$dir"|
|# Copy each app backup separately. Not as elegant as a single scp command but should be fine.|
|doneCount=0|
|for i in apps
|do|
|appIdapps[$i
|numi + 1
|echo num of $appCount] Downloading $appId
|if scp "$username@$serverIp:/home/master/applications/$appId/local_backups/backup.tgz" appId.tgz" ; then|
|echo "👍 Done
|doneCountdoneCount + 1
|else|
|echo "🙁 Could not download $appId
|fi|
|done|
|# Final report|
|if doneCount == 0)) ; then|
|echo "😱 All downloads failed
|elif doneCount == $appCount)) ; then|
|echo "😊 All downloads succeeded
|else|
|echo "🤨 Some downloads failed
|fi|