Merge branch 'main' into dev
This commit is contained in:
commit
280ea9e2b0
3 changed files with 45 additions and 18 deletions
45
README.md
45
README.md
|
@ -1,23 +1,46 @@
|
||||||
|
<div align=center>
|
||||||
|
|
||||||
# Backup-CloudPanel-Nextcloud
|
# Backup-CloudPanel-Nextcloud
|
||||||
*BorgBackup Script - CloudPanel, Nextcloud
|
#### BorgBackup Script - CloudPanel, Nextcloud
|
||||||
|
|
||||||
[![foxly.de](https://foxly.de/media/223-github-logo-png/)](https://foxly.de)
|
[![Commits](https://img.shields.io/github/last-commit/foxly-it/Backup-CloudPanel-Nextcloud?style=flat-square)](https://github.com/foxly-it/Backup-CloudPanel-Nextcloud/commits/main) [![GitHub release](https://img.shields.io/github/release/foxly-it/Backup-CloudPanel-Nextcloud?style=flat-square)](https://github.com/foxly-it/Backup-CloudPanel-Nextcloud/releases) [![GitHub license](https://img.shields.io/github/license/foxly-it/Backup-CloudPanel-Nextcloud?style=flat-square&color=lightgray)](LICENSE.md) [![GitHub file size in bytes](https://img.shields.io/github/size/foxly-it/Backup-CloudPanel-Nextcloud/backup.sh?style=flat-square)](https://github.com/foxly-it/Backup-CloudPanel-Nextcloud/blob/main/Backup-CloudPanel-Nextcloud.sh)
|
||||||
|
---
|
||||||
|
[![foxly.de](https://foxly.de/media/232-png-bild-png/)](https://foxly.de)
|
||||||
|
---
|
||||||
|
</div>
|
||||||
|
|
||||||
[![Blog](https://img.shields.io/static/v1.svg?color=FF6C54&labelColor=55555&logoColor=ffffff&style=for-the-badge&label=Foxly.de&message=IT-Blog)](https://foxly.de "How-To guides, opinions and much more!")
|
This script is designed for [CloudPanel](CloudPanel.io). It backs up all data located in ```/home/cloudpanel``` to a Borgbackup repository. Furthermore, before the actual backup process, all databases that are specified are backed up and stored in ```/home/cloudpanel/backup```. In the script itself you have to define which database is used, e.g. MySQL/MariaDB or PostgreSQL. Adjustments that need to be changed in the script are marked with TODO.
|
||||||
[![GitHub](https://img.shields.io/static/v1.svg?color=FF6C54&labelColor=55555&logoColor=ffffff&style=for-the-badge&label=Foxly.de&message=GitHub)](https://github.com/foxly-it "view the source for all of our repositories.")
|
In the script a Nextcloud instance is also considered, should this function not be used, it can simply be commented out.
|
||||||
[![CloudPanel](https://img.shields.io/static/v1.svg?color=398fdb&labelColor=55555&logoColor=ffffff&style=for-the-badge&label=CloudPanel.io&message=Nextcloud)](https://foxly.de/category-article-list/5-nextcloud/ "Installation Guides.")
|
|
||||||
|
|
||||||
|
Of course, this script can be adapted to other systems.
|
||||||
|
|
||||||
This backupscript is designed to be simple. It is adapted for [CloudPanel](CloudPanel.io). Of course there is also a focus on Nextcloud.
|
---
|
||||||
|
|
||||||
It backs up both the databases and the files.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
First, a BorgBackup repository must be created.
|
In order to back up data, a repository must first be created. This can be created locally or on a remote computer via ssh.
|
||||||
|
|
||||||
|
*local:*
|
||||||
```
|
```
|
||||||
borg init --encryption=repokey /path/to/backup
|
borg init --encryption=repokey /path/to/backup
|
||||||
```
|
```
|
||||||
|
*remote:*
|
||||||
|
```
|
||||||
|
borg init --encryption=repokey user@server.ip.or.domain:/path/to/backup
|
||||||
|
```
|
||||||
|
|
||||||
Now you can adjust the script to your needs.
|
---
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* MariaDB/MySQL support
|
||||||
|
* PostgreSQL support
|
||||||
|
* Nextcloud support
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Operating System
|
||||||
|
|
||||||
|
#### Recommended
|
||||||
|
|
||||||
|
* Debian 10 (__Buster__)
|
||||||
|
* Raspbian 10 (__Buster__)
|
||||||
|
|
18
backup.sh
18
backup.sh
|
@ -20,8 +20,10 @@ NUM_CORES=$(nproc || echo 1)
|
||||||
####################
|
####################
|
||||||
# Helper functions #
|
# Helper functions #
|
||||||
####################
|
####################
|
||||||
|
|
||||||
backup_VER="v1.2.2"
|
backup_VER="v1.2.2"
|
||||||
|
|
||||||
|
|
||||||
str_repeat() {
|
str_repeat() {
|
||||||
printf -v v "%-*s" "$1" ""
|
printf -v v "%-*s" "$1" ""
|
||||||
echo "${v// /$2}"
|
echo "${v// /$2}"
|
||||||
|
@ -105,7 +107,8 @@ domain="nextcloud.domain.tld"
|
||||||
# Here you can assign a password (Borg passphrase) for the Borg backup archive.
|
# Here you can assign a password (Borg passphrase) for the Borg backup archive.
|
||||||
backupPassword="P@ssw0rd"
|
backupPassword="P@ssw0rd"
|
||||||
# Here you have to specify the path to the Borg repository.
|
# Here you have to specify the path to the Borg repository.
|
||||||
backupRepo="/mnt/backup/path"
|
|
||||||
|
backupRepo="/path/to/Repo"
|
||||||
|
|
||||||
#####################################################
|
#####################################################
|
||||||
# TODO Database - MariaDB/MySQL or PostgreSQL #
|
# TODO Database - MariaDB/MySQL or PostgreSQL #
|
||||||
|
@ -133,6 +136,7 @@ echo -e "\e[93mStart PostgreSQL database backup"
|
||||||
databases="DATABASENAME"
|
databases="DATABASENAME"
|
||||||
mkdir -p /home/cloudpanel/backups/$databases #
|
mkdir -p /home/cloudpanel/backups/$databases #
|
||||||
postbackupdir="/home/cloudpanel/backups/$databases" #
|
postbackupdir="/home/cloudpanel/backups/$databases" #
|
||||||
|
|
||||||
sudo -u postgres pg_dump $databases > $postbackupdir/BBNC-$(date +%d-%m-%Y_%H-%M-%S).sql #
|
sudo -u postgres pg_dump $databases > $postbackupdir/BBNC-$(date +%d-%m-%Y_%H-%M-%S).sql #
|
||||||
echo -e "${FGREEN}Backup has been finished successfully after $(displaytime $(($(date +%s) - START)))!${FEND}" #
|
echo -e "${FGREEN}Backup has been finished successfully after $(displaytime $(($(date +%s) - START)))!${FEND}" #
|
||||||
#########################################################################################################################################################################
|
#########################################################################################################################################################################
|
||||||
|
@ -161,7 +165,7 @@ export BORG_REPO=$backupRepo
|
||||||
export BORG_PASSPHRASE=$backupPassword
|
export BORG_PASSPHRASE=$backupPassword
|
||||||
|
|
||||||
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
|
||||||
trap 'echo $( date ) Backup unterbrochen >&2; exit 2' INT TERM
|
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
|
||||||
|
|
||||||
info "Start backup"
|
info "Start backup"
|
||||||
|
|
||||||
|
@ -181,12 +185,12 @@ backup_exit=$?
|
||||||
echo ""
|
echo ""
|
||||||
sudo -u $user php$phpversion $clpLocation$domain/occ maintenance:mode --off
|
sudo -u $user php$phpversion $clpLocation$domain/occ maintenance:mode --off
|
||||||
echo ""
|
echo ""
|
||||||
echo "Ende des Backups:"
|
echo "End of the backup:"
|
||||||
echo "Storage space usage of the backups:"
|
echo "Storage space usage of the backups:"
|
||||||
echo ""
|
echo ""
|
||||||
df -h ${backupRepo}
|
df -h ${backupRepo}
|
||||||
|
|
||||||
info "Loeschen von alten Backups"
|
info "Delete old backups"
|
||||||
# Automatically delete old backups
|
# Automatically delete old backups
|
||||||
borg prune \
|
borg prune \
|
||||||
--prefix '{hostname}-' \
|
--prefix '{hostname}-' \
|
||||||
|
@ -200,10 +204,10 @@ prune_exit=$?
|
||||||
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
|
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
|
||||||
|
|
||||||
if [ ${global_exit} -eq 0 ]; then
|
if [ ${global_exit} -eq 0 ]; then
|
||||||
echo -e "${FGREEN}Backup und/oder Prune erfolgreich beendet nach $(displaytime $(($(date +%s) - START)))!${FEND}"
|
echo -e "${FGREEN}Backup and/or Prune successfully completed after $(displaytime $(($(date +%s) - START)))!${FEND}"
|
||||||
elif [ ${global_exit} -eq 1 ]; then
|
elif [ ${global_exit} -eq 1 ]; then
|
||||||
echo -e "${FYELLOW}Backup und/oder Prune beendet mit Warungen nach $(displaytime $(($(date +%s) - START)))!${FEND}"
|
echo -e "${FYELLOW}Backup and/or Prune ends with warnings after $(displaytime $(($(date +%s) - START)))!${FEND}"
|
||||||
else
|
else
|
||||||
echo -e "${FRED}Backup und/oder Prune beendet mit Fehlern nach $(displaytime $(($(date +%s) - START)))!${FEND}"
|
echo -e "${FRED}Backup and/or Prune exits with errors after $(displaytime $(($(date +%s) - START)))!${FEND}"
|
||||||
fi
|
fi
|
||||||
exit ${global_exit}
|
exit ${global_exit}
|
||||||
|
|
Loading…
Reference in a new issue