#
# Bash script for creating backups of Nextcloud.
#
-# Version 1.0.0
+# Version 2.0.0
#
# Usage:
# - With backup directory specified in the script: ./NextcloudBackup.sh
backupMainDir='/media/hdd/nextcloud_backup'
fi
-echo "Backup directory: $backupMainDir"
-
currentDate=$(date +"%Y%m%d_%H%M%S")
# The actual directory of the current backup - this is a subdirectory of the main directory above with a timestamp
# TODO: Your web server user
webserverUser='www-data'
-# TODO: The name of the database system (ome of: mysql, mariadb, postgresql)
+# TODO: The name of the database system (one of: mysql, mariadb, postgresql)
databaseSystem='mariadb'
# TODO: Your Nextcloud database name
# TODO: The maximum number of backups to keep (when set to 0, all backups are kept)
maxNrOfBackups=0
+# TODO: Ignore updater's backup directory in the data directory to save space
+# Set to true to ignore the backup directory
+ignoreUpdaterBackups=false
+
# File names for backup files
# If you prefer other file names, you'll also have to change the NextcloudRestore.sh script.
fileNameBackupFileDir='nextcloud-filedir.tar.gz'
fileNameBackupDataDir='nextcloud-datadir.tar.gz'
-# TOOD: Uncomment if you use local external storage
+# TODO: Uncomment if you use local external storage
#fileNameBackupExternalDataDir='nextcloud-external-datadir.tar.gz'
fileNameBackupDb='nextcloud-db.sql'
echo "Maintenance mode still enabled."
fi
+ echo "Starting web server..."
+ systemctl start "${webserverServiceName}"
+ echo "Done"
+ echo
+
exit 1
}
+#
+# Print information
+#
+echo "Backup directory: ${backupMainDir}"
+
#
# Check for root
#
# Backup data directory
#
echo "Creating backup of Nextcloud data directory..."
-tar -cpzf "${backupdir}/${fileNameBackupDataDir}" -C "${nextcloudDataDir}" .
+
+if [ "$ignoreUpdaterBackups" = true ] ; then
+ echo "Ignoring updater backup directory"
+ tar -cpzf "${backupdir}/${fileNameBackupDataDir}" --exclude="updater-*/backups/*" -C "${nextcloudDataDir}" .
+else
+ tar -cpzf "${backupdir}/${fileNameBackupDataDir}" -C "${nextcloudDataDir}" .
+fi
+
echo "Done"
echo
echo "Backup Nextcloud database (PostgreSQL)..."
if ! [ -x "$(command -v pg_dump)" ]; then
- errorecho "ERROR:PostgreSQL not installed (command pg_dump not found)."
+ errorecho "ERROR: PostgreSQL not installed (command pg_dump not found)."
errorecho "ERROR: No backup of database possible!"
else
PGPASSWORD="${dbPassword}" pg_dump "${nextcloudDatabase}" -h localhost -U "${dbUser}" -f "${backupdir}/${fileNameBackupDb}"
echo
echo "DONE!"
-echo "Backup created: ${backupdir}"
\ No newline at end of file
+echo "Backup created: ${backupdir}"