3 Commits

4 changed files with 176 additions and 1 deletions

View File

@@ -1,4 +1,21 @@
## Creates a docker image of debian + Apache + PHP + Maria DB. ## Creates a docker image of debian + Apache + PHP + Maria DB.
# Build the Image and run a Container to test the restore of your cloud_backup. # Build the Image and run a Container to test the restore of your cloud_backup.
FROM debian:Bookworm FROM docker.io/library/debian:bookworm
MAINTAINER Stephan Wittig <>
RUN apt update && apt upgrade -y
RUN apt install --no-install-recommends -y \
mariadb-server \
apache2 \
php8.2 \
&& :
##
RUN mkdir -p /opt/cloud_backup \
&& :
WORKDIR /opt/cloud_backup

14
test/compose.yaml Normal file
View File

@@ -0,0 +1,14 @@
version: '3'
services:
cloudrestore:
image: cloud_backup_test
build:
context: cloudrestore
dockerfile: Dockerfile
ports:
- "8080:80"
environment:
- CLOUD_RESTORE
volumes:
- ./scripts:/opt/cloud_backup:cached
command: sleep infinity

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# Path to nextclouds data folder
CONFIG_NC_DATA="/srv/nextcloud-data"
# Path to the web root of the nextcloud
CONFIG_NC_BASE="/var/www/nextcloud"
# Folder for the log file - relative to nextcloud data folder!
CONFIG_NC_LOGPATH="admin/files/System/"
# Where to find the file with folders to exclude from backup
CONFIG_EXCLUDE=/home/cloudbackup/.config/cloud_backup.exclude
# Host of the database
CONFIG_NC_DB_SERVER=localhost
# Name of the nextcloud database
CONFIG_NC_DB_NAME=nextclouddb
# User for the nextcloud datbase
CONFIG_NC_DB_USER=nextclouduser
# Folders to backup with rsync
BACKUP_SOURCES=(/srv/nextcloud-data /var/www/nextcloud)
# Target server for backup
TOSSH=
# port to use for ssh/rsync
SSHPORT=10110
# User for the backup server
SSHUSER="cloudbackup"
# target folder on the backup server
BACKUP_TARGET="/srv/dev-disk-by-label-mirny/Backup/nubecula-minor/nextcloud"

117
test/scripts/cloud_restore.sh Executable file
View File

@@ -0,0 +1,117 @@
#!/bin/bash
## Restores the cloud configuration, data and database from backup done with cloud_backup.
# Log levels for messages
LLMute=0
LLMdtry=1 # mandatory: messages that are always written to the log (except mute)
LLError=2
LLWarning=3
LLInfo=4
LLDebug=5
## Actual log level of the logger used
Log_Level=$LLDebug
## base name of the logging script.
Log_Name="${0##*/}";
## Write log of the script.
## $1 Loglevel to log the message with.
## $2 message to log.
function logger() {
local _logging_level=$1;
local _log_message=$2;
if [[ $Log_Level -lt $_logging_level ]]; then
return;
fi
local _now=$($DATE +%Y%m%d_%H:%M:%S);
if [[ $_logging_level -eq $LLInfo ]]; then
_type=" Info:";
elif [[ $_logging_level -eq $LLError ]]; then
_type=" ERROR!";
elif [[ $_logging_level -eq $LLWarning ]]; then
_type=" Warning:";
elif [[ $_logging_level -eq $LLDebug ]]; then
_type=" DEBUG:";
else
_type=":";
fi
printf "$Log_Name ${_now}${_type} ${_log_message}\n" >> $Log_File;
if [[ $Log_Level -eq $LLDebug ]]; then
printf "${_now}${_type} ${_log_message}\n";
fi
}
## Cleanup and exit with exit value given.
function clean_up() {
local _exit_val=$1;
logger $LLInfo "Cleaning up on exit $_exit_val.";
logger $LLMdtry "Exiting on $_exit_val.";
exit $_exit_val;
}
## Returns the binaries full path if existent.
function which_is() {
declare -n _ret_val=$1; # declare RETVAL a reference of $1
local _executable=$2;
local _with_full_path=$(which ${_executable} 2>/dev/null);
if [ -x "$_with_full_path" ]; then
_ret_val="$_with_full_path";
return 0;
else
_ret_val="$_executable not found!";
return 1;
fi
}
function create_folders() {
logger $LLDebug "CONFIG_NC_DATA: mkdir -p $CONFIG_NC_DATA";
if [[ ! -n "$CONFIG_NC_DATA" ]]; then clean_up 1; fi
mkdir -p "$CONFIG_NC_DATA"; # Path to nextclouds data folder
logger $LLDebug "CONFIG_NC_BASE: mkdir -p $CONFIG_NC_BASE";
if [[ ! -n "$CONFIG_NC_BASE" ]]; then clean_up 1; fi
mkdir -p "$CONFIG_NC_BASE"; # Path to the web root of the nextcloud
for _source in "$BACKUP_SOURCES"; do
logger $LLDebug "BACKUP_SOURCES: mkdir -p $_source";
mkdir -p "$_source";
done;
logger $LLDebug "BACKUP_TARGET: mkdir -p $BACKUP_TARGET";
if [[ ! -n "$BACKUP_TARGET" ]]; then clean_up 1; fi
mkdir -p "$BACKUP_TARGET"; # target folder on the backup server
}
CONFIG_NC_DB_SERVER=localhost # Host of the database
# Name of the nextcloud database
CONFIG_NC_DB_NAME=nextclouddb
# User for the nextcloud datbase
CONFIG_NC_DB_USER=nextclouduser
# Target server for backup
TOSSH=
# port to use for ssh/rsync
SSHPORT=10110
# User for the backup server
SSHUSER="cloudbackup"
which_is DATE 'date';
if [ $? -ne 0 ]; then echo $DATE; exit 1; fi
## Logfile in nextcloud to have a visible result.
Run_Date=$($DATE +%Y_%m_%d)
Log_File="/tmp/${Run_Date}_cloudrestore.log";
if [[ ! -f "./cloud_backup.conf" ]]; then
clean_up 1;
fi
source ./cloud_backup.conf
create_folders;
if [[ $? -ne 0 ]]; then
clean_up 1;
fi
clean_up 0;