https://www.raphael-muench.de/docs/nextcloud_backup.html

Nextcloud Backup

Bash Backup Script
Cron job
Setting access rights



Bash Backup bash Script

This is a very simple bash script for creating a daily tarball file of different folders on my server!
In combination with a regular cron job I have different backups for the last 7 days available.


Download here => backup.sh

#!/bin/bash
################################################################################
#                              backup.sh                                       #
#                                                                              #
# Use this template as the beginning of a new program. Place a short           #
# decription of the script here.                                               #
#                                                                              #
# Change History                                                               #
# 04/03/2019  Raphael Muench	     This is simple backup script              #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
################################################################################
################################################################################
################################################################################
#                                                                              #
#  Copyright (C) 2019 Raphael Muench                                           #
#  raphael@raphael-muench.de                                                   #
#                                                                              #
#  This program is free software; you can redistribute it and/or modify        #
#  it under the terms of the GNU General Public License as published by        #
#  the Free Software Foundation; either version 2 of the License, or           #
#  (at your option) any later version.                                         #
#                                                                              #
#  This program is distributed in the hope that it will be useful,             #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of              #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
#  GNU General Public License for more details.                                #
#                                                                              #
#  You should have received a copy of the GNU General Public License           #
#  along with this program; if not, write to the Free Software                 #
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   #
#                                                                              #
################################################################################
################################################################################
################################################################################

backup_folder=/private-backup
today="$(date +'%d-%m-%Y')"


# Delete all files which modified date is older than one week
find $backup_folder/*.tar.gz -mtime 7 -exec rm {} \;

# Create a tarball for all www stuff
tar cvzf /root/Backup-$today-www.tar.gz /var/www/html/nextcloud/ &

# Create a SQL dump
mysqldump --single-transaction -h localhost -u user -p database --password="xxxxxxxx"> /root/Backup-$today-Nextcloud.sql &

# Create an archive file for all etc stuff
tar cvzf /root/Backup-$today-etc.tar.gz /etc/ &


Cron job

sudo crontab -e

0 1 * * * /root/backup.sh


Setting access rights

sudo chmod 0700 backup.sh



Copyright (c) 2017, 2018, 2019 Raphael Münch, last change: 2019-04-03
Valid HTML 5.0