feat: functional backup & semi-functional restore
Restore is limited until I can test just dumping the sql file in the db Backup works fully and rescans files. Patch is part of the backup initiative to solidify our backup strategy
This commit is contained in:
parent
e2ade64929
commit
66642ba905
102
abra.sh
102
abra.sh
|
@ -1,5 +1,101 @@
|
|||
NC_APP_DIR="app:/var/www/html"
|
||||
|
||||
sub_occ(){
|
||||
abra__service_="app"
|
||||
abra___user="www-data"
|
||||
sub_app_run php /var/www/html/occ "$@"
|
||||
# shellcheck disable=SC2034
|
||||
abra__service_="app"
|
||||
# shellcheck disable=SC2034
|
||||
abra___user="www-data"
|
||||
sub_app_run php /var/www/html/occ "$@"
|
||||
}
|
||||
|
||||
_backup_app() {
|
||||
# Copied _abra_backup_dir to make UX better on restore and backup
|
||||
{
|
||||
abra__src_="$1"
|
||||
abra__dst_="-"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
FILENAME="$(basename "$1").tar"
|
||||
|
||||
debug "Copying '$1' to '$FILENAME'"
|
||||
|
||||
silence
|
||||
mkdir -p /tmp/abra
|
||||
sub_app_cp > /tmp/abra/$FILENAME
|
||||
unsilence
|
||||
}
|
||||
|
||||
next_maintenance_on() {
|
||||
silence
|
||||
sub_occ maintenance:mode --on > /dev/null
|
||||
unsilence
|
||||
debug "Nextcloud maintenance mode enabled"
|
||||
}
|
||||
|
||||
next_maintenance_off() {
|
||||
silence
|
||||
sub_occ maintenance:mode --off > /dev/null
|
||||
unsilence
|
||||
debug "Nextcloud maintenance mode disabled"
|
||||
}
|
||||
|
||||
abra_backup_app() {
|
||||
# shellcheck disable=SC2154
|
||||
ARK_FILENAME="$ABRA_BACKUP_DIR/${abra__app_}_app_$(date +%F).tar.gz"
|
||||
# Cant be FILENAME as that gets changed by something
|
||||
next_maintenance_on
|
||||
_backup_app $NC_APP_DIR/config
|
||||
_backup_app $NC_APP_DIR/data
|
||||
_backup_app $NC_APP_DIR/themes
|
||||
# Combine archives
|
||||
tar -Af /tmp/abra/config.tar /tmp/abra/data.tar
|
||||
tar -Af /tmp/abra/config.tar /tmp/abra/themes.tar
|
||||
gzip /tmp/abra/config.tar -c > "$ARK_FILENAME"
|
||||
rm /tmp/abra/*.tar
|
||||
success "Backed up 'app' to $ARK_FILENAME"
|
||||
next_maintenance_off
|
||||
}
|
||||
|
||||
abra_backup_db() {
|
||||
next_maintenance_on
|
||||
_abra_backup_mysql "db" "nextcloud"
|
||||
next_maintenance_off
|
||||
}
|
||||
|
||||
abra_backup() {
|
||||
abra_backup_app && abra_backup_db
|
||||
}
|
||||
|
||||
|
||||
abra_restore_app() {
|
||||
next_maintenance_on
|
||||
# shellcheck disable=SC2034
|
||||
{
|
||||
abra__src_="-"
|
||||
abra__dst_=$NC_APP_DIR
|
||||
}
|
||||
|
||||
zcat "$@" | sub_app_cp
|
||||
|
||||
next_maintenance_off
|
||||
sub_occ files:scan --all > /dev/null # Needs to be run in normal mode
|
||||
success "Restored 'app'"
|
||||
}
|
||||
|
||||
# abra_restore_db() {
|
||||
# warning "Restoring the database is on a existing app and not a new one has not been tested. Use with caution."
|
||||
# next_maintenance_on
|
||||
# # 3wc: unlike abra_backup_db, we can assume abra__service_ will be 'db' if we
|
||||
# # got this far..
|
||||
|
||||
# # shellcheck disable=SC2034
|
||||
# abra___no_tty="true"
|
||||
|
||||
# DB_PASSWORD=$(sub_app_run cat /run/secrets/db_password)
|
||||
|
||||
# zcat "$@" | sub_app_run mysql -u root -p"$DB_PASSWORD" wordpress
|
||||
|
||||
# success "Restored 'db'"
|
||||
# next_maintenance_off
|
||||
# }
|
||||
|
|
Reference in New Issue