Backups are critical for any production ERPNext instance. Losing your ERP data means losing invoices, inventory records, and customer information. This guide shows you how to set up automated daily backups with offsite storage.

STEP 1 Manual Backup (Understanding the Basics)

cd frappe-bench
bench --site mysite.local backup

This creates three files in the sites/mysite.local/private/backups directory:

# Database backup
20260410_120000-mysite_local-database.sql.gz

# Files backup (uploaded documents)
20260410_120000-mysite_local-files.tar

# Private files backup
20260410_120000-mysite_local-private-files.tar

STEP 2 Backup With File Uploads

bench --site mysite.local backup --with-files

STEP 3 Create a Backup Script

nano /home/erpnext/backup.sh
#!/bin/bash
BENCH_DIR="/home/erpnext/frappe-bench"
SITE="mysite.local"
BACKUP_DIR="/home/erpnext/backups"
DATE=$(date +%Y%m%d)

cd $BENCH_DIR
bench --site $SITE backup --with-files

# Copy to backup directory
mkdir -p $BACKUP_DIR/$DATE
cp sites/$SITE/private/backups/*$DATE* $BACKUP_DIR/$DATE/

# Delete backups older than 30 days
find $BACKUP_DIR -type d -mtime +30 -exec rm -rf {} +

echo "Backup completed: $DATE"
chmod +x /home/erpnext/backup.sh

STEP 4 Schedule With Cron

crontab -e

Add this line to run the backup every day at 2 AM:

0 2 * * * /home/erpnext/backup.sh >> /home/erpnext/backup.log 2>&1

STEP 5 Upload to S3 (Offsite Backup)

sudo apt install -y awscli
aws configure

Add this to your backup script:

aws s3 sync $BACKUP_DIR/$DATE s3://your-bucket-name/erpnext-backups/$DATE/

STEP 6 Restore From Backup

bench --site mysite.local restore 
  /path/to/database-backup.sql.gz 
  --with-private-files /path/to/private-files.tar 
  --with-public-files /path/to/files.tar

Test your restore process at least once a month. A backup you can’t restore from is not a backup — it’s just a file taking up disk space.

Share this article

Comments

Join the discussion. Got a question, found an issue, or want to share your experience?

Leave a Comment

Your email stays private. We just use it for replies.

Nothing to preview yet.

Use **bold**, *italic*, `code`, ```code blocks```, [link](url), > quote, - list