2 Commits

Author SHA1 Message Date
swg
aa7af00b78 Fixed not existing variable to . 2025-10-07 22:19:44 +01:00
swg
9e55f74777 README.md aktualisiert
Consistent name for user executing the backup.
2024-10-29 08:37:36 +00:00
6 changed files with 7 additions and 182 deletions

View File

@@ -33,7 +33,7 @@ The script throws out a log file of its activities. It is meant to be visible in
To give unrestricted access to everything via sudo is not a good idea. I'd choose to restrict elevated permissions to the specific commands needed.
In the sudoers file add the following lines.
I chose `cloudbackup`to be the user for doing the backup, you are free to chose anything else. In the sudoers file add the following lines.
```
# Cmnd alias specification
@@ -47,8 +47,8 @@ cloudbackup ALL=(www-data) NOPASSWD: OCC_NC, RSYNC
cloudbackup ALL=(www-data) NOPASSWD: MAINTENANCE_ON, MAINTENANCE_OFF
```
### cronjob
in crontab create an entry for the `cloud_backup.sh`. Replace `user` with yours doing the backup.
in crontab create an entry for the `cloud_backup.sh`. Replace `cloudbackup` with yours doing the backup.
```
# Nextcloud backup
12 1 * * 1 user /home/cloudbackup/cloud_backup.sh
12 1 * * 1 cloudbackup /home/cloudbackup/cloud_backup.sh
```

View File

@@ -180,9 +180,9 @@ for SOURCE in "${BACKUP_SOURCES[@]}"; do
if [ $? -ne 0 ]; then logger $LLERROR "Rsync of $SOURCE failed!"; fi
done
if [ "$S" ] && [ "$TOSSH" ] && [ -z "$FROMSSH" ]; then
logger $LLDEBUG "$S $TOSSH $LN -nsf $TARGET$TODAY $TARGET$LAST";
logger $LLINFO "Setting Link to last to »$TARGET$TODAY«";
$S $TOSSH "$LN -nsf $TARGET$TODAY $TARGET$LAST";
logger $LLDEBUG "$S $TOSSH $LN -nsf $BACKUP_TARGET$TODAY $BACKUP_TARGET$LAST";
logger $LLINFO "Setting Link to last to »$BACKUP_TARGET$TODAY«";
$S $TOSSH "$LN -nsf $BACKUP_TARGET$TODAY $BACKUP_TARGET$LAST";
if [ $? -ne 0 ]; then logger $LLERROR "Resetting link to last backup of todays failed!"; clean_up 1; fi
fi
logger $LLMDTRY "Backup of nextcloud done, cleaning up.";

View File

@@ -1,21 +1,4 @@
## 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.
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
FROM debian:Bookworm

View File

@@ -1,14 +0,0 @@
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

@@ -1,27 +0,0 @@
#!/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"

View File

@@ -1,117 +0,0 @@
#!/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;