====== Backup ====== To backup a Nextcloud installation there are five main things you need to retain: #. The config folder #. The custom apps folder (only if you have custom apps installed) #. The data folder #. The theme folder #. The database Maintenance mode ---------------- ``maintenance:mode`` locks the sessions of logged-in users and prevents new logins in order to prevent inconsistencies of your data. You must run ``occ`` as the HTTP user, like this example on Ubuntu Linux:: $ sudo -E -u www-data php occ maintenance:mode --on You may also put your server into this mode by editing :file:`config/config.php`. Change ``"maintenance" => false`` to ``"maintenance" => true``: :: true, Don't forget to change it back to ``false`` when you are finished. Backup folders -------------- Copy your config, data, and theme directories to a location outside your Nextcloud environment. Alternatively, copy your entire Nextcloud installation directory (including the data directory). You could use this command:: rsync -Aavx nextcloud/ nextcloud-dirbkp_`date +"%Y%m%d"`/ Backup database --------------- .. warning:: Before restoring a backup see :doc:`restore` MariaDB ^^^^^^^ MariaDB is the recommended database engine. To backup MariaDB using `mariadb-dump `_:: mariadb-dump --single-transaction -h [server] -u [username] -p[password] [db_name] > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak If you have enabled MariaDB 4-byte support (:doc:`../configuration_database/mysql_4byte_support`, needed for emoji), add ``--default-character-set=utf8mb4``:: mariadb-dump --single-transaction --default-character-set=utf8mb4 -h [server] -u [username] -p[password] [db_name] > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak MySQL ^^^^^ To backup MySQL:: mysqldump --single-transaction -h [server] -u [username] -p[password] [db_name] > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak If you have enabled MySQL 4-byte support (:doc:`../configuration_database/mysql_4byte_support`, needed for emoji), add ``--default-character-set=utf8mb4``:: mysqldump --single-transaction --default-character-set=utf8mb4 -h [server] -u [username] -p[password] [db_name] > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak SQLite ^^^^^^ :: sqlite3 data/owncloud.db .dump > nextcloud-sqlbkp_`date +"%Y%m%d"`.bak PostgreSQL ^^^^^^^^^^ :: PGPASSWORD="password" pg_dump [db_name] -h [server] -U [username] -f nextcloud-sqlbkp_`date +"%Y%m%d"`.bak