Skip to content

Instantly share code, notes, and snippets.

@diginfo
Last active May 14, 2020 10:03
Show Gist options
  • Save diginfo/c0012c609d693b7f4782671f2e0056ae to your computer and use it in GitHub Desktop.
Save diginfo/c0012c609d693b7f4782671f2e0056ae to your computer and use it in GitHub Desktop.
Pure Site Backups
#!/bin/bash
## STAMPS - @@ VALUES SET LATER
NOW=$(date +%y%m%d%H%M)
DOW=$(date +"%a")
S3="/usr/bin/s3cmd";
SRC="/usr/share/nodejs/sites/"
S3DIR="s3://sg-180222/pure/sites/"
# /usr/bin/s3cmd sync $SRC $S3DIR
function daily {
echo "@@ Pushing Daily Sqlite Backups"
for SPATH in $SRC*
do
if [ -d "$SPATH" ]; then
SITE=$(basename $SPATH);
if [ -z $ARG ] || [ "$ARG" == "$SITE" ] ;then
DB="$SPATH/data/*.db"
DPATH="$S3DIR$SITE/data/daily/$DOW/"
CMD="$S3 -p put $DB $DPATH"
echo "$CMD";
$CMD;
fi
fi
done
}
## execute a function on all or 1 site.
function sites {
for SPATH in $SRC*
do
if [ -d "$SPATH" ]; then
SITE=$(basename $SPATH);
if [ -z $ARG ] || [ "$ARG" == "$SITE" ] ;then
CMD="$S3 del --force --recursive s3://sg-180222/pure/sites/$SITE/data/sqlite"
############
echo "$CMD";
$CMD;
fi
fi
done
}
## Backup-SYNC Entire Site Data
function data {
echo "@@ Pushing Public Files Backups"
for SPATH in $SRC*
do
if [ -d "$SPATH" ]; then
SITE=$(basename $SPATH);
if [ -z $ARG ] || [ "$ARG" == "$SITE" ] ;then
DATA="$SPATH"
DPATH="$S3DIR"
CMD="$S3 sync --progress $DATA $DPATH"
echo "$CMD";
$CMD
fi
fi
done
}
ARG=$1
#sites;
daily;
data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment