Automated Backup Script for Faveo on Docker (Files and Database)

Faveo Docker backup

Introduction

This guide sets up automatic backups for Faveo Helpdesk running on Docker.

Each backup run creates two files:

Backup file What it contains
<database>-db-<date>.sql.gz The Faveo database, exported from the running MySQL container
<domain>-filesystem-<date>.tar.gz The Faveo application folder (faveo/) and the storage/ folder (attachments, uploads)

The backups are saved on the same server and, if you want, a copy is also uploaded to another server using FTP, SFTP / SCP or a Windows (SMB) share. Old backups are deleted automatically after the number of days you choose.

The backup runs while Faveo stays online. Nothing in your Faveo installation is changed. On a large database, saving changes in Faveo may pause for a moment while the database is being exported, so schedule backups for a quiet time of day.

This guide covers both:

  • Debian based systems: Ubuntu, Debian
  • RedHat based systems: RHEL, Alma Linux, Rocky Linux

Where the commands differ, each step has a separate block for each OS family. Run only the block that matches your server.

Installed Faveo with faveo-run.sh? The installer also has a built-in one-time backup (sudo ./faveo-run.sh --backup), described in the Faveo on Docker guide. Use this script when you want backups to run automatically on a schedule and, optionally, be copied to another server.


Before You Start

Make sure the following are true:

  • Faveo Helpdesk is running on Docker on this server.
  • The database runs in the local MySQL container of that installation (named <your-domain>-mysql). Installations that use an external / remote database server are not supported by this script.
  • You have sudo (root) access to the server.

Quick overview of the steps

Step What you do
1 Install the required tools
2 Download the backup script
3 Find your Faveo Docker folder
4 Fill in config.py
5 Add remote upload details (optional)
6 Run a test backup
7 Schedule automatic backups
8 Restore a backup (when needed)

Step 1: Install the Required Tools

Debian / Ubuntu:

sudo apt update
sudo apt install -y python3 tar gzip cron curl

RedHat / Alma / Rocky:

sudo dnf install -y python3 tar gzip cronie curl
sudo systemctl enable --now crond

Only if you will upload backups using SFTP / SCP, also install Paramiko:

Debian / Ubuntu:

sudo apt install -y python3-paramiko

RedHat / Alma / Rocky:

sudo dnf install -y epel-release
sudo dnf install -y python3-paramiko

On RHEL, if epel-release is not found, use: sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm

Only if you will upload backups to a Windows (SMB) share, also install the SMB client:

Debian / Ubuntu:

sudo apt install -y smbclient

RedHat / Alma / Rocky:

sudo dnf install -y samba-client

Step 2: Download the Backup Script

Create a folder for the script and download its files:

sudo mkdir -p /opt/faveo-docker-backup
cd /opt/faveo-docker-backup

for f in config.py docker_backup_common.py dockerlocal.py dockerftp.py dockerscp.py dockersmb.py cron.sh; do
  sudo curl -fsSL --connect-timeout 20 -o "$f" "https://raw.githubusercontent.com/ladybirdweb/faveo-server-images/master/scripts/docker-backup-script/$f" || echo "Download failed: $f"
done

sudo chmod +x *.py cron.sh
ls -l

The download takes a few seconds. No Download failed line should be shown, and none of the files may be 0 bytes in the ls -l output. If a download fails, check that this server can reach raw.githubusercontent.com (internet access, proxy or firewall) and run the commands again.

You should see these files:

File What it does
config.py The only file you edit. Your paths and (optional) upload details.
dockerlocal.py Backup, stored on this server only
dockerftp.py Backup, plus upload to an FTP server
dockerscp.py Backup, plus upload to an SFTP / SCP server
dockersmb.py Backup, plus upload to a Windows (SMB) share
cron.sh Sets up the automatic schedule
docker_backup_common.py Shared code used by the scripts above. Do not run it directly.

Step 3: Find Your Faveo Docker Folder

The backup script needs the folder where your Faveo Docker installation lives. It is the folder that contains both docker-compose.yml and .env.

  • If you installed with faveo-run.sh, it is usually /opt/faveo/<your-domain>. List them with:

      ls /opt/faveo
    
  • If you set up Docker by hand, it is the folder where you ran docker compose up.

Check that you have the right folder (replace the path with yours):

ls /opt/faveo/support.example.com/docker-compose.yml /opt/faveo/support.example.com/.env

Both files must be listed.

Write down whether .env contains HOST_ROOT_DIR. You need this in the next step:

sudo grep HOST_ROOT_DIR /opt/faveo/support.example.com/.env
  • A line such as HOST_ROOT_DIR=faveo is shown: nothing extra to do.
  • Nothing is shown (this is normal for installations made with faveo-run.sh): you will set HOST_ROOT_DIR_OVERRIDE in Step 4.

Step 4: Fill In config.py

Open the configuration file:

sudo nano /opt/faveo-docker-backup/config.py

Change these values at the top of the file:

PROJECT_DIR = "/opt/faveo/support.example.com"
BACKUP_DIRECTORY = "/var/backups/faveo"
LOG_FILE = "/var/backups/faveo/backup.log"
LOCAL_BACKUP_RETENTION = 7
Setting What to enter
PROJECT_DIR Your Faveo Docker folder from Step 3.
BACKUP_DIRECTORY Where the backups are saved on this server. Choose a folder outside PROJECT_DIR with enough free disk space. It is created automatically.
LOG_FILE Where the backup log is written. Inside BACKUP_DIRECTORY is fine.
LOCAL_BACKUP_RETENTION How many days to keep backups on this server, for example 7. See the warning below.

Important: set LOCAL_BACKUP_RETENTION. Its default value (5 / (24 * 60)) is 5 minutes, so every backup run deletes all older backups on this server. That default is only suitable when you also upload backups to another server (Step 5). If you keep backups only on this server, change it to the number of days to keep, for example 7, or you will only ever have the latest backup.

If .env has no HOST_ROOT_DIR (see Step 3), also set:

HOST_ROOT_DIR_OVERRIDE = "faveo"

Recommended: also back up your Docker configuration. By default only faveo/ and storage/ are backed up. To be able to rebuild Faveo on a new server, you also need your Docker settings and certificates. Set:

EXTRA_BACKUP_PATHS = [".env", "docker-compose.yml", "apache", "supervisor", "Dockerfile", "ssl_copy", "certbot"]

Items that do not exist in your installation are skipped automatically, so you can use this line as it is.

Leave every other setting as it is. The domain name, database name, MySQL root password and MySQL container name are read automatically from your Faveo .env file.

Save the file, then make it readable by root only (it will contain passwords if you use remote upload):

sudo chmod 600 /opt/faveo-docker-backup/config.py

Protect the backup folder. The backups contain your whole database and, with the recommended setting above, your .env file with its passwords. Create the folder now and make it accessible to root only:

sudo mkdir -p /var/backups/faveo
sudo chmod 700 /var/backups/faveo

Step 5: Add Remote Upload Details (Optional)

Skip this step if you only want backups on this server.

Scroll down in config.py and fill in only the section for the method you use. Leave the other sections as they are.

FTP (used by dockerftp.py):

FTP_HOST = "ftp.example.com"
FTP_PORT = 21
FTP_USER = "ftp-username"
FTP_PASS = "ftp-password"
REMOTE_DIR = "/faveo-backups"

SFTP / SCP (used by dockerscp.py):

SCP_HOST = "sftp.example.com"
SCP_PORT = 22
SCP_USER = "sftp-username"
SCP_PASS = "sftp-password"
SCP_REMOTE_DIR = "/faveo-backups"

Windows / SMB share (used by dockersmb.py):

SMB_SERVER = "fileserver.example.com"
SMB_SHARE = "Faveo Backup"
SMB_USER = "smb-username"
SMB_PASS = "smb-password"
SMB_REMOTE_DIR = ""
Setting What to enter
REMOTE_DIR / SCP_REMOTE_DIR A folder that already exists on the remote server.
SMB_REMOTE_DIR Optional subfolder inside the share. Leave "" to use the share itself. The folder must already exist, and its name must not contain spaces.
BACKUP_RETENTION (near the top of the file) How many days to keep backups on the remote server. Default 7.

Step 6: Run a Test Backup

Run the script that matches how you want to store backups:

Store backups Command
On this server only sudo python3 dockerlocal.py
+ upload to FTP sudo python3 dockerftp.py
+ upload to SFTP / SCP sudo python3 dockerscp.py
+ upload to Windows (SMB) sudo python3 dockersmb.py

For example:

cd /opt/faveo-docker-backup
sudo python3 dockerlocal.py

The last line must say ... backup completed successfully. Then check that the two backup files were created:

ls -lh /var/backups/faveo/

You should see one ...-db-<date>.sql.gz file and one ...-filesystem-<date>.tar.gz file. If you used remote upload, also check that both files are on the remote server.

If the last line says finished with errors, read the messages above it and see Troubleshooting.


Step 7: Schedule Automatic Backups

Run the scheduler from the script folder:

cd /opt/faveo-docker-backup
sudo bash cron.sh

Answer the questions:

It asks What to answer
Add or remove the cron job? add
Have you filled in config.py? yes
Directory path for the scripts /opt/faveo-docker-backup
Cron interval 1 Daily, 2 Weekly (Sundays) or 3 Monthly (1st of the month)
Time of day A time like 23:30, or press Enter for midnight
Store Locally or Remote? B for this server only, A for remote upload
(Remote only) Which method? C for SFTP / SCP, D for FTP, E for SMB

You should see Cron job set up successfully.

Check the schedule:

sudo crontab -l

You should see one line ending in dockerlocal.py, dockerftp.py, dockerscp.py or dockersmb.py, for example:

30 23 * * * cd /opt/faveo-docker-backup && python3 /opt/faveo-docker-backup/dockerlocal.py >> /opt/faveo-docker-backup/backup.log 2>&1

To change the schedule or the storage method, run sudo bash cron.sh again and choose add. The old schedule is replaced. To stop automatic backups, run it and choose remove.

🎉 Your Faveo Docker backups now run automatically.


Step 8: Restore a Backup

Use these steps only when you need to bring back data from a backup. The examples use the folders from this guide; replace the paths, the file names and the domain with yours.

1. Go to your Faveo Docker folder and load its settings:

cd /opt/faveo/support.example.com
DB=$(sudo grep ^MYSQL_DATABASE= .env | cut -d= -f2-)
PW=$(sudo grep ^MYSQL_ROOT_PASSWORD= .env | cut -d= -f2-)
DOMAIN=$(sudo grep ^DOMAINNAME= .env | cut -d= -f2-)

2. Restore the database:

gunzip -c /var/backups/faveo/<database>-db-<date>.sql.gz | sudo docker exec -i -e MYSQL_PWD="$PW" "$DOMAIN-mysql" mysql -u root "$DB"

3. Restore the files (faveo/, storage/ and, if you set EXTRA_BACKUP_PATHS, your configuration files):

sudo tar -xzf /var/backups/faveo/<domain>-filesystem-<date>.tar.gz -C /opt/faveo/support.example.com

To restore only the Faveo files and keep your current configuration, add the folder names at the end: ... -C /opt/faveo/support.example.com faveo storage

4. Restart Faveo:

sudo docker compose restart

On older servers that only have the standalone tool, use sudo docker-compose restart.

Tip: Restoring overwrites the current data. If unsure, first take a fresh backup (Step 6), so you can go back if needed.


Troubleshooting

Problem Cause and fix
Could not resolve required setting(s) ['HOST_ROOT_DIR'] Your .env has no HOST_ROOT_DIR (normal for installations made with faveo-run.sh). Set HOST_ROOT_DIR_OVERRIDE = "faveo" in config.py (Step 4).
Could not resolve required setting(s) [...] with other names PROJECT_DIR does not point to your Faveo Docker folder, or that folder’s .env is incomplete. Check the path with the commands in Step 3. If the database is on a remote server, this script is not supported.
MySQL backup failed: container '...-mysql' is not running The MySQL container is stopped or has a different name. Run sudo docker ps and look for the MySQL container. If its name is not <your-domain>-mysql, set MYSQL_CONTAINER = "<actual name>" in config.py.
Only the newest backup is kept on this server LOCAL_BACKUP_RETENTION is still at its 5-minute default. Set it to the number of days to keep, for example 7 (Step 4).
FTP upload failed / SFTP or SMB error Wrong host, port, username or password, or the remote folder does not exist. Check the details in Step 5 and that this server can reach the remote server (firewall).
No module named 'paramiko' Paramiko is missing. Install it as shown in Step 1.
smbclient: command not found The SMB client is missing. Install it as shown in Step 1.
config.py not found The scripts were not run from /opt/faveo-docker-backup, or config.py was not downloaded. Repeat Step 2.
Test backup works but scheduled backups do not run The cron service is not running. Debian / Ubuntu: sudo systemctl enable --now cron. RedHat / Alma / Rocky: sudo systemctl enable --now crond. Then check the schedule with sudo crontab -l.

Useful commands

# Run a backup now (store on this server only)
cd /opt/faveo-docker-backup && sudo python3 dockerlocal.py

# List the backups on this server
ls -lh /var/backups/faveo/

# View the latest backup log entries
sudo tail -n 30 /var/backups/faveo/backup.log

# Show the backup schedule
sudo crontab -l

# Check the MySQL container is running
sudo docker ps --filter "name=-mysql"

Updated: