Added backuptool and logs directory
This commit is contained in:
parent
8b7ed750d8
commit
b910951e9b
7
bin/.env
7
bin/.env
@ -4,9 +4,14 @@
|
||||
# Company name
|
||||
#COMPANY="Fang Free Inc"
|
||||
|
||||
# Country
|
||||
# Country
|
||||
#COUNTRY="US"
|
||||
|
||||
# Administrator password
|
||||
#ADMINPASS="password123"
|
||||
|
||||
# Backblaze KeyID (Master Key)
|
||||
B2_APPLICATION_KEY_ID="3239c6765fdc"
|
||||
|
||||
# Backblaze Application Key
|
||||
B2_APPLICATION_KEY="0050ac8837466cbca0e0aa574b5f8332f706a5e26c"
|
||||
|
136
bin/backuptool
Executable file
136
bin/backuptool
Executable file
@ -0,0 +1,136 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Federated Backup / Restore Tool to B2 Backblaze
|
||||
. /federated/lib/functions.sh
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
Backup to Backblaze
|
||||
Usage: $0 [options] service
|
||||
Arguments:
|
||||
service Service to backup or 'all' for all services
|
||||
Options
|
||||
-l List files in a backup
|
||||
-b Perform backup of a service
|
||||
-d Delete backups of a service
|
||||
-r Restore a backup of a service
|
||||
EOF
|
||||
exit 2;
|
||||
}
|
||||
createbucket() {
|
||||
if [ ! -f "/federated/bin/.b2init" ]; then
|
||||
UUID=`uuid`
|
||||
B2_APPLICATION_KEY_ID="$B2_APPLICATION_KEY_ID" B2_APPLICATION_KEY="$B2_APPLICATION_KEY" /federated/bin/b2-linux create_bucket $UUID allPrivate
|
||||
echo "$UUID" > /federated/bin/.b2init
|
||||
fi
|
||||
}
|
||||
listbackup() {
|
||||
echo "* Listing backup files in $SERVICE.."
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity list-current-files b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$SERVICE/
|
||||
}
|
||||
backupservice() {
|
||||
echo "* Backing up $SERVICE.."
|
||||
|
||||
if [ "$SERVICE" = "postgresql" ]; then
|
||||
docker exec postgresql /bin/bash -c "pg_dumpall -c -U postgres | gzip -9 > /docker-entrypoint-initdb.d/dump_`date +%m-%d-%Y`.sql.gz"
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity /federated/apps/$SERVICE b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$SERVICE/
|
||||
rm /federated/apps/postgresql/data/docker-entrypoint-initdb.d/dump_*
|
||||
else
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity /federated/apps/$SERVICE b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$SERVICE/
|
||||
fi
|
||||
}
|
||||
backupserviceall() {
|
||||
echo "* Backing up all services.."
|
||||
|
||||
for i in "${SERVICES[@]}"; do
|
||||
echo "** Backing up $i.."
|
||||
if [ "$SERVICE" = "postgresql" ]; then
|
||||
docker exec postgresql /bin/bash -c "pg_dumpall -c -U postgres | gzip -9 > /docker-entrypoint-initdb.d/dump_`date +%m-%d-%Y`.sql.gz"
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity /federated/apps/$i b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$i/
|
||||
rm /federated/apps/postgresql/data/docker-entrypoint-initdb.d/dump_*
|
||||
else
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity /federated/apps/$i b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$i/
|
||||
fi
|
||||
done
|
||||
}
|
||||
deletebackup() {
|
||||
mkdir -p /federated/tmp/empty
|
||||
cd /federated/tmp/empty && /federated/bin/b2-linux sync --allowEmptySource --delete . b2://$UUID/$SERVICE/
|
||||
cd /federated && rm -rf /federated/tmp/empty
|
||||
}
|
||||
restorebackup() {
|
||||
echo "* Restoring $SERVICE.."
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity --force b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$SERVICE/ /federated/apps/$SERVICE
|
||||
}
|
||||
restorebackupall() {
|
||||
echo "* Restoring all services.."
|
||||
for i in "${SERVICES[@]}"; do
|
||||
echo "** Restoring $i.."
|
||||
PASSPHRASE=$GPG_PASSPHRASE duplicity --force b2://$B2_APPLICATION_KEY_ID:$B2_APPLICATION_KEY@$UUID/$i/ /federated/apps/$i
|
||||
done
|
||||
}
|
||||
while getopts "lbdr" OPTION; do
|
||||
case $OPTION in
|
||||
l)
|
||||
LIST_BACKUP="true";
|
||||
;;
|
||||
b)
|
||||
RUN_BACKUP="true";
|
||||
;;
|
||||
d)
|
||||
RUN_DELETE="true";
|
||||
;;
|
||||
r)
|
||||
RUN_RESTORE="true";
|
||||
;;
|
||||
*)
|
||||
usage;
|
||||
exit 2;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
usage;
|
||||
fi
|
||||
SERVICE=$2
|
||||
|
||||
if [ -f "/federated/bin/.gpg.backblaze" ]; then
|
||||
GPG_PASSPHRASE=`cat /federated/bin/.gpg.backblaze`
|
||||
else
|
||||
GPG_PASSPHRASE=$(create_password);
|
||||
echo "$GPG_PASSPHRASE" > /federated/bin/.gpg.backblaze
|
||||
fi
|
||||
|
||||
if [ -f "/federated/bin/.env" ]; then
|
||||
. /federated/bin/.env
|
||||
[ -z "$B2_APPLICATION_KEY_ID" ] && failcheck "/federated/bin/.env doesn't include B2_APPLICATION_KEY_ID for backups"
|
||||
[ -z "$B2_APPLICATION_KEY" ] && failcheck "/federated/bin/.env doesn't include B2_APPLICATION_KEY for backups"
|
||||
else
|
||||
failcheck "Could not find an .env file."
|
||||
fi
|
||||
|
||||
[ -f "/federated/bin/.b2init" ] && UUID=`cat /federated/bin/.b2init`
|
||||
[ $LIST_BACKUP ] && listbackup
|
||||
[ $RUN_DELETE ] && deletebackup
|
||||
|
||||
if [ $RUN_RESTORE ]; then
|
||||
if printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then
|
||||
restorebackup
|
||||
elif [ "$SERVICE" = "all" ]; then
|
||||
restorebackupall
|
||||
else
|
||||
failcheck "$SERVICE is not a valid service"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $RUN_BACKUP ]; then
|
||||
if printf '%s\0' "${SERVICES[@]}" | grep -Fxqz -- "$SERVICE"; then
|
||||
createbucket
|
||||
backupservice
|
||||
elif [ "$SERVICE" = "all" ]; then
|
||||
createbucket
|
||||
backupserviceall
|
||||
else
|
||||
failcheck "$SERVICE is not a valid service"
|
||||
fi
|
||||
fi
|
@ -93,6 +93,8 @@ for i in dns postgresql ldap mail collabora proxy nextcloud matrix element listm
|
||||
start_$i
|
||||
done
|
||||
|
||||
add_cron
|
||||
|
||||
# Print out federated environment details
|
||||
print_details
|
||||
echo -ne "\n\n"
|
@ -27,6 +27,10 @@ spin() {
|
||||
done
|
||||
done
|
||||
}
|
||||
add_cron() {
|
||||
(crontab -l; echo "30 23 * * * /federated/bin/backup.sh >> /federated/logs/backup.log 2>&1") | sort -u | crontab -
|
||||
(crontab -l; echo "0 2 * * * /federated/bin/upgrade.sh >> /federated/logs/upgrade.log 2>&1") | sort -u | crontab -
|
||||
}
|
||||
install_federated() {
|
||||
[ -d "/federated" ] && fail "Directory /federated already exists. Already installed?"
|
||||
API_TOKEN="92d97f5aa371d420ebce7bc9a008ea8c6ec5d334"
|
||||
|
0
logs/.gitignore
vendored
Normal file
0
logs/.gitignore
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user