GithubHelp home page GithubHelp logo

decatec / nextcloud-backup-restore Goto Github PK

View Code? Open in Web Editor NEW
123.0 10.0 35.0 80 KB

Moved to codeberg.org - https://codeberg.org/DecaTec/Nextcloud-Backup-Restore - Bash scripts for backup/restore of Nextcloud

Home Page: https://decatec.de

License: MIT License

Shell 100.00%
nextcloud bash script backup restore

nextcloud-backup-restore's Introduction

Get it on Codeberg

⚠️ Archived, moved to Codeberg: https://codeberg.org/DecaTec/Nextcloud-Backup-Restore ⚠️

release

Nextcloud-Backup-Restore

This repository contains two bash scripts for backup/restore of Nextcloud.

It is based on a Nextcloud installation using nginx and MariaDB (see the (German) tutorial Nextcloud auf Ubuntu Server 20.04 LTS mit nginx, MariaDB, PHP, Let’s Encrypt, Redis und Fail2ban).

General information

For a complete backup of any Nextcloud instance, you'll have to backup these items:

  • The Nextcloud file directory (usually /var/www/nextcloud)
  • The data directory of Nextcloud (it's recommended that this is not located in the web root, so e.g. /var/nextcloud_data)
  • The Nextcloud database
  • Maybe a local external storage mounted into Nextcloud

The scripts take care of these items to backup automatically.

Requirements

  • pigz (https://zlib.net/pigz/) when using backup compression. If not installed already, it can be installed with apt install pigz (Debian/Ubuntu). If not available, you can use another compression algorithm (e.g. gzip)

Important notes about using the scripts

  • After cloning or downloading the scripts, these need to be set up by running the script setup.sh (see below).
  • If you do not want to use the automated setup, you can also use the file NextcloudBackupRestore.conf.sample as a starting point. Just make sure to rename the file when you are done (cp NextcloudBackupRestore.conf.sample NextcloudBackupRestore.conf)
  • The configuration file NextcloudBackupRestore.conf has to be located in the same directory as the scripts for backup/restore.
  • The scripts assume that Nextcloud's data directory is not a subdirectory of the Nextcloud installation (file directory). The general recommendation is that the data directory should not be located somewhere in the web folder of your webserver (usually /var/www/), but in a different folder (e.g. /var/nextcloud_data). For more information, see here.
  • However, if your data directory is located under the Nextcloud file directory, you'll have to change the script configuration (file NextcloudBackupRestore.conf after running setup.sh) so that the data directory is not part of the backup/restore (otherwise, it would be copied twice).
  • The scripts only backup the Nextcloud data directory and can backup a local external storage mounted into Nextcloud. If you have any other external storage mounted in Nextcloud (e.g. FTP), these files have to be handled separately.
  • The scripts support MariaDB/MySQL and PostgreSQL as database.
  • You should have enabled 4 byte support (see Nextcloud Administration Manual) on your Nextcloud database. Otherwise, when you have not enabled 4 byte support, you have to edit the restore script, so that the database is not created with 4 byte support enabled (variable dbNoMultibyte).

Setup

  1. Clone the repository: git clone https://codeberg.org/DecaTec/Nextcloud-Backup-Restore.git
  2. Set permissions:
    • chown -R root Nextcloud-Backup-Restore
    • cd Nextcloud-Backup-Restore
    • chmod 700 *.sh
  3. Call the (interactive) script for automated setup (this will create a file NextcloudBackupRestore.conf containing the desired configuration): ./setup.sh
  4. Important: Check this configuration file if everything was set up correctly (see TODO in the configuration files's comments)
  5. Start using the scripts: See sections Backup and Restore below

Keep in mind that the configuration file NextcloudBackupRestore.conf hast to be located in the same directory as the scripts for backup/restore, otherwise the configuration will not be found.

Backup

In order to create a backup, simply call the script NextcloudBackup.sh on your Nextcloud machine. If this script is called without parameter, the backup is saved in a directory with the current time stamp in your main backup directory: As an example, this would be /media/hdd/nextcloud_backup/20170910_132703. The backup script can also be called with a parameter specifiying the main backup directory, e.g. ./NextcloudBackup.sh /media/hdd/nextcloud_backup. In this case, the directory specified will be used as main backup directory.

You can also call this script by cron. Example (at 2am every night, with log output):

0 2 * * * /path/to/scripts/Nextcloud-Backup-Restore/NextcloudBackup.sh > /path/to/logs/Nextcloud-Backup-$(date +\%Y\%m\%d\%H\%M\%S).log 2>&1

Restore

For restore, just call NextcloudRestore.sh. This script expects at least one parameter specifying the name of the backup to be restored. In our example, this would be 20170910_132703 (the time stamp of the backup created before). The full command for a restore would be ./NextcloudRestore.sh 20170910_132703. You can also specify the main backup directory with a second parameter, e.g. ./NextcloudRestore.sh 20170910_132703 /media/hdd/nextcloud_backup.

nextcloud-backup-restore's People

Contributors

bernieo avatar decatec avatar mahmoudakl avatar mmartinortiz avatar pcanterino avatar timkrief avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nextcloud-backup-restore's Issues

Nextcloud ends up in installation mode after running the script

Hey there,

for some reason my Nextcloud ends up with a config with only a 'instanceid' => 'theinstanceid', left in it after the backup process.

Any idea why this happens?

System:
PHP 7.1.11
Apache
Latest Nextcloud 13.0.1

So looks like if it fails because no space left this happens :/

`Backup Nextcloud database...
mysqldump: Error: 'Disk full (/tmp/#sql_a3a_2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")' when trying to dump tablespaces
mysqldump: Couldn't execute 'show fields from `oc_accounts`': Disk full (/tmp/#sql_a3a_0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device") (1021)
Done

Starting web server...
Starting apache2 (via systemctl): apache2.service.
Done

Switching off maintenance mode...
Nextcloud is not installed - only a limited number of commands are available

                                                                  
  [Symfony\Component\Console\Exception\CommandNotFoundException]  
  Command "maintenance:mode" is not defined.                      
  Did you mean this?                                              
      maintenance:install              `

Is there any way to get it to stop the script instead of activate the install mode on errors? :)

Greetings,
Chris

Wrong variable declaration in restore script

Hello,

first at all thank you for your scripts.

I found a little false variable declaration in your restore script (NextcloudRestore.sh)+

In line 18 the variable is called "backupMainDir":
backupMainDir="/mnt/Share/NextcloudBackups/"

But in line 20 "mainBackupdir":
currentRestoreDir="${mainBackupdir}/${restore}"

So you have to change line 18:
mainBackupdir="/mnt/Share/NextcloudBackups/"

So thats the working restore script:
NextcloudRestore.txt

kind regards

no issue, just thank you

I would like to thank you in this way only for the exact instructions on your homepage and for the scripts.
This makes it easier for me to manage my 3 Cloud instances immensely

best regards, Terrar

| instead of & in NextcloudRestore

tl;dr: in line 73 replace | with &

The number of parameters will always be not equal to one OR not equal to two. What you want is to check if the number is NOT (equal to one OR equal to two), so if you dissolve this bracket you get (NOT equal to one) AND (NOT equal to two).

Add an interrupt action

Hi.

Is it possible to add an interrupt action that will automatically go out of maintenance mode if a user hits Ctrl-C?

Thanks.

Cheers,
kekePower

Backup to FTP-Server

After using the backup i transfer it always to my FTP.
What do you think about implementing a feature to save the backups directly on an FTP-Server?
Is this possible to realize?

Question: Adjust keep maxNrOfBackups logic to keep of the last x days and then one per month

Hi,

is there a possibility to adjust the logic for keeping old backups?

TODO: The maximum number of backups to keep (when set to 0, all backups are kept)
maxNrOfBackups=0

My requirements:

  • I like to create daily backup files
  • I like to keep all backup files of the last 7 days
  • outside the 7 days I like to keep one file per month for the last xx month

-> as a result I would have the backups of the current week and then one per month for e.g. one year.

Any idea?

Thanks a lot.
Chingato

tipo on line 20

NextcloudRestore.sh

currentRestoreDir="${mainBackupdir}/${restore}"
correct: currentRestoreDir="${mainBackupDir}/${restore}"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.