Skip to content

Commit

Permalink
Version: 5.0.0! - see changelog.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
pothi committed Dec 8, 2022
1 parent 3d81a15 commit 2a5b930
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 720 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ The above is applicable to all the scripts!

## Contributors

The following people have contributed to this repo in various ways...
Thanks to the following people who have contributed to this repo...

- [Nik](https://github.com/nik-lampe)
- [Francesco](https://github.com/Cicciodev)
- [Wischweh Mobile Consultancy](https://github.com/wischweh)

### How to decrypt, if I used a passphrase

Expand Down
90 changes: 90 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
version: 5.0.0
- date: 2022-12-08
- Add user bin directories and snap bin to PATH.
- a new common changelog.txt file.
- mention the actual script name in the output / log.
- migrate laravel and php backup scripts to their own repo.
- remove redundant check for aws cli.
- better documentation.

Before 5.0.0, separate changelogs were used.

db-backup.sh

version: 3.2.3
- minor fixes
version: 3.2.2
- date: 2022-11-29
- rewrite logic while attempting to create required directories
- add requirements section
version: 3.2.1
- date: 2021-07-14
- aws cli add option "--only-show-errors"
version: 3.2.0
- date: 2021-03-27
- improve naming scheme.
version: 3.1.1
- date: 2020-11-24
- improve documentation.

full-backup.sh

version: 4.0.3
- multiple fixes
version: 4.0.2
- date: 2022-11-29
- rewrite logic while attempting to create required directories
- add requirements section
version: 4.0.1
- date: 2021-08-30
- fix a minor bug
version: 4.0.0
- date: 2021-06-06
- simplify excludes in tar command
- simplify naming scheme for encrypted backups
- show only errors while uploading to S3. Not even progress bar.
version: 3.2.0
- date: 2021-03-27
- improve naming scheme.
changelog
version: 3.1.1
- date: 2020-11-24
- improve documentation
version: 3.1.0
- delete old backups in $ENCRYPTED_BACKUP_PATH only if this directory / path exists


files-backup-without-uploads.sh

version: 3.1.2
- date: 2022-11-29
- rewrite logic while attempting to create required directories
v3.1.1
- date: 2020-11-24
- improve documentation
v2
- date 2017-09-13
- change of script name
- change the output file name
- remove older backups using a simple find command; props - @wpbullet
v1.1.2
- date 2017-09-04
- dynamically find the location of aws cli
v1.1.1
- date 2017-09-03
- change the default dir name from Backup to backups
- no more syncing by default
v1.1
- date 2017-05-05
- moved to nightly backups
- started excluding wp core files and uploads
- uploads files are now synced, rather than taken as part of regular nightly backup
v1.0.4
- date 2017-03-06
- support for hard-coded variable AWS S3 Bucket Name
- support for environment files (.envrc / .env)
- skipped version 1.0.3
v1.0.2
- date 2017-03-06
- support for hard-coded variable $DOMAIN

68 changes: 18 additions & 50 deletions db-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,10 @@
# requirements
# ~/log, ~/backups, ~/path/to/example.com/public

# version - 3.2.3

# changelog
# version: 3.2.3
# - minor fixes
# version: 3.2.2
# - date: 2022-11-29
# - rewrite logic while attempting to create required directories
# - add requirements section
# version: 3.2.1
# - date: 2021-07-14
# - aws cli add option "--only-show-errors"
# version: 3.2.0
# - date: 2021-03-27
# - improve naming scheme.
# version: 3.1.1
# - date: 2020-11-24
# - improve documentation.
# version - 5.0.0

### Variables - Please do not add trailing slash in the PATHs

# To enable offsite backups...
# apt install awscli (or yum install awscli)
# legacy method
# run 'pip install awscli' (as root)
# aws configure (as normal user)

# where to store the database backups?
BACKUP_PATH=${HOME}/backups/db-backups
ENCRYPTED_BACKUP_PATH=${HOME}/backups/encrypted-db-backups
Expand All @@ -55,14 +32,11 @@ DOMAIN=
# AWS Variable can be hard-coded here
AWS_S3_BUCKET_NAME=

# ref: http://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_PROFILE=

#-------- Do NOT Edit Below This Line --------#

# to capture non-zero exit code in the pipeline
set -o pipefail

# attempt to create log directory if it doesn't exist
[ -d "${HOME}/log" ] || mkdir -p ${HOME}/log
if [ "$?" -ne "0" ]; then
Expand Down Expand Up @@ -91,8 +65,6 @@ log_file=${HOME}/log/backups.log
exec > >(tee -a ${log_file} )
exec 2> >(tee -a ${log_file} >&2)

echo "Script started on... $(date +%c)"

export PATH=~/bin:~/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

declare -r script_name=$(basename "$0")
Expand All @@ -110,6 +82,8 @@ if [ -z "$aws_cli" ]; then
exit 1
fi

echo "'$script_name' started on... $(date +%c)"

let AUTODELETEAFTER--

# get environment variables, if exists
Expand All @@ -126,35 +100,33 @@ if [ "$DOMAIN" == "" ]; then
if [ "$WP_DOMAIN" != "" ]; then
DOMAIN=$WP_DOMAIN
else
echo 'Usage ${script_name} example.com (S3 bucket name)'; exit 1
echo "Usage $script_name example.com (S3 bucket name)"; exit 1
fi
else
DOMAIN=$1
fi
fi

WP_PATH=${SITES_PATH}/$DOMAIN/${PUBLIC_DIR}
[ ! -d "$WP_PATH" ] && echo "WordPress is not found at $WP_PATH" && exit 1

if [ "$AWS_BUCKET" == "" ]; then
if [ "$BUCKET_NAME" == "" ]; then
if [ "$2" != "" ]; then
AWS_BUCKET=$2
BUCKET_NAME=$2
elif [ "$AWS_S3_BUCKET_NAME" != "" ]; then
AWS_BUCKET=$AWS_S3_BUCKET_NAME
BUCKET_NAME=$AWS_S3_BUCKET_NAME
fi
fi

# WordPress root
WP_PATH=${SITES_PATH}/${DOMAIN}/${PUBLIC_DIR}
[ ! -d "$WP_PATH" ] && echo "WordPress is not found at $WP_PATH" && exit 1

# convert forward slash found in sub-directories to hyphen
# ex: example.com/test would become example.com-test
DOMAIN_FULL_PATH=$(echo $DOMAIN | awk '{gsub(/\//,"_")}; 1')
DOMAIN_FULL_PATH=$(echo $DOMAIN | awk '{gsub(/\//,"-")}; 1')

DB_OUTPUT_FILE_NAME=${BACKUP_PATH}/${DOMAIN_FULL_PATH}-${timestamp}.sql.gz
ENCRYPTED_DB_OUTPUT_FILE_NAME=${ENCRYPTED_BACKUP_PATH}/db-${DOMAIN_FULL_PATH}-${timestamp}.sql.gz
DB_LATEST_FILE_NAME=${BACKUP_PATH}/${DOMAIN_FULL_PATH}-latest.sql.gz

# to capture non-zero exit code in the pipeline
set -o pipefail

# take actual DB backup
if [ -f "$wp_cli" ]; then
$wp_cli --path=${WP_PATH} transient delete --all
Expand All @@ -177,15 +149,11 @@ else
fi

# external backup
if [ "$AWS_BUCKET" != "" ]; then
if [ ! -e "$aws_cli" ] ; then
echo; echo 'Did you run "pip install aws && aws configure"'; echo;
fi

if [ "$BUCKET_NAME" != "" ]; then
if [ -z "$PASSPHRASE" ] ; then
$aws_cli s3 cp $DB_OUTPUT_FILE_NAME s3://$AWS_BUCKET/${DOMAIN_FULL_PATH}/db-backups/ --only-show-errors
$aws_cli s3 cp $DB_OUTPUT_FILE_NAME s3://$BUCKET_NAME/${DOMAIN_FULL_PATH}/db-backups/ --only-show-errors
else
$aws_cli s3 cp $ENCRYPTED_DB_OUTPUT_FILE_NAME s3://$AWS_BUCKET/${DOMAIN_FULL_PATH}/encrypted-db-backups/ --only-show-errors
$aws_cli s3 cp $ENCRYPTED_DB_OUTPUT_FILE_NAME s3://$BUCKET_NAME/${DOMAIN_FULL_PATH}/encrypted-db-backups/ --only-show-errors
fi
if [ "$?" != "0" ]; then
echo; echo 'Something went wrong while taking offsite backup';
Expand Down
50 changes: 8 additions & 42 deletions files-backup-without-uploads.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
#!/bin/bash

# version: 3.1.2

# Changelog
# version: 3.1.2
# - date: 2022-11-29
# - rewrite logic while attempting to create required directories
# v3.1.1
# - date: 2020-11-24
# - improve documentation
# v2
# - date 2017-09-13
# - change of script name
# - change the output file name
# - remove older backups using a simple find command; props - @wpbullet
# v1.1.2
# - date 2017-09-04
# - dynamically find the location of aws cli
# v1.1.1
# - date 2017-09-03
# - change the default dir name from Backup to backups
# - no more syncing by default
# v1.1
# - date 2017-05-05
# - moved to nightly backups
# - started excluding wp core files and uploads
# - uploads files are now synced, rather than taken as part of regular nightly backup
# v1.0.4
# - date 2017-03-06
# - support for hard-coded variable AWS S3 Bucket Name
# - support for environment files (.envrc / .env)
# - skipped version 1.0.3
# v1.0.2
# - date 2017-03-06
# - support for hard-coded variable $DOMAIN
# version: 5.0.0

# Variable
AUTODELETEAFTER=30
Expand All @@ -52,6 +19,9 @@ BUCKET_NAME=

#-------- Do NOT Edit Below This Line --------#

# to capture non-zero exit code in the pipeline
set -o pipefail

# attempt to create log directory if it doesn't exist
[ -d "${HOME}/log" ] || mkdir -p ${HOME}/log
if [ "$?" -ne 0 ]; then
Expand Down Expand Up @@ -97,6 +67,8 @@ if [ -z "$aws_cli" ]; then
exit 1
fi

echo "'$script_name' started on... $(date +%c)"

let AUTODELETEAFTER--

# get environment variables, if exists
Expand All @@ -113,7 +85,7 @@ if [ "$DOMAIN" == "" ]; then
if [ "$WP_DOMAIN" != "" ]; then
DOMAIN=$WP_DOMAIN
else
echo "Usage ${script_name} domainname.com (S3 bucket name)"; exit 1
echo "Usage $script_name example.com (S3 bucket name)"; exit 1
fi
else
DOMAIN=$1
Expand All @@ -128,12 +100,10 @@ if [ "$BUCKET_NAME" == "" ]; then
fi
fi

# path to be backed up
# WordPress root
WP_PATH=${SITES_PATH}/${DOMAIN}/${PUBLIC_DIR}
[ ! -d "$WP_PATH" ] && echo "WordPress is not found at $WP_PATH" && exit 1

echo "Script started on... $(date +%c)"

# path to be excluded from the backup
# no trailing slash, please
EXCLUDE_BASE_PATH=${DOMAIN}
Expand Down Expand Up @@ -162,10 +132,6 @@ BACKUP_FILE_NAME=${BACKUP_PATH}/files-without-uploads-${DOMAIN}-$timestamp.tar.g
tar hczf ${BACKUP_FILE_NAME} -C ${SITES_PATH} ${EXCLUDES} ${DOMAIN} &> /dev/null

if [ "$BUCKET_NAME" != "" ]; then
if [ ! -e "$aws_cli" ] ; then
echo; echo 'Did you run "pip install aws && aws configure"'; echo;
fi

$aws_cli s3 cp ${BACKUP_FILE_NAME} s3://$BUCKET_NAME/${DOMAIN}/files-backup-without-uploads/ --only-show-errors
if [ "$?" != "0" ]; then
echo; echo 'Something went wrong while taking offsite backup'; echo
Expand Down
Loading

0 comments on commit 2a5b930

Please sign in to comment.