BACKUP ERP Next

is there anyone that can assist with an easy method to backup an ERP NEXT/frappe
installation?
I have tried multiple methods including using Duplicati
I fail at every method.

Maybe you can try this
mysqldump -h $DBHOST -u $SITE -p $DBUSER > yourfile.sql

I Struggle to restore backups that I create.
these are the steps i follow:

  1. create a container:
    docker run -v /var/lib/mysql --name jacotest ubuntu /bin/bash

  2. here I make a backup of a working ERP NEXT/DOCKER installation:
    docker run --rm --volumes-from frappe_docker-db-1 -v ${pwd}:/db-data-backup ubuntu tar cvf /db-data-backup/db-data-backup.tar -C /var/lib/mysql .

  3. then i create a new ERPNEXT/DOCKER installation on a new pc, get that up and running.

  4. then i restore the previous made backup in point 2 from the first pc onto the new pc with the following:
    docker run --rm --volumes-from frappe_docker-db-1 -v ${pwd}:/backup ubuntu bash -c “cd /var/lib/mysql && tar xvf /backup/db-data-backup.tar”

all these steps seems to work, but upon a docker restart ERP NEXT no longer runs in the web browser on the new pc.

why does this happen?

Backing up databases doesn’t work like that. If you just compress or copy them live, they will be in an inconsistent state.

1 Like

thank you for the response. i will work through the steps.
the first step gives me an error regarding gzip not working.
not sure if gzip must be somehow activated? or if theser inputs are infact outdated and need some changes?

docker compose -f /compose/file/location/docker-compose.yml exec db sh -c ‘exec mariadb-dump --single-transaction -uroot -p"$MYSQL_ROOT_PASSWORD" database_name_here’ | gzip > /on/host/backup/destination/database-$(date +%Y%m%d_%H%M%S).sql.gz

What is the exact error message? Please post it here.

Also to narrow it down, perhaps just skip gzip for troubleshooting purposes and redirect the output to an uncompressed .sql file like this to see if the problem is with gzip or something else before gzip:

docker compose -f /compose/file/location/docker-compose.yml exec db sh -c 'exec mariadb-dump --single-transaction -uroot -p"$MYSQL_ROOT_PASSWORD" database_name_here' > /on/host/backup/destination/database-$(date +%Y%m%d_%H%M%S).sql

error message when running your input:

gzip: The term ‘gzip’ is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I will follow your instruction on using it without gzip.

Below is my input that I use

docker compose -f /git/frappe_docker/compose.yml exec db sh -c ‘exec mariadb-dump --single-transaction -uroot p"123" /var/lib/mysql/frappe_docker-db-1’ > /git/testing/backup/database-${date +%Y%m%d_%H%M%

S}.sql

Then I get the following error:

mariadb-dump: Got error: 1045: “Access denied for user ‘root’@‘localhost’ (using password: NO)” when trying to connect

I have tried multiple passwords that i assume it could be, also the default since the installation are new and i do not believe it should be different from the default.
is there a file or location i can go and check what the pasword currently is?

Yes, it’s in site_config.json and in your compose.yml

But database is going to be your database name, not the path to a folder or file. Execute"show databases" in mariadb-client from your db container to find the name, or get it from site_config.json.

my docker compose file (named pwd.yml) shows the below info:

environment:
MYSQL_ROOT_PASSWORD:
MARIADB_ROOT_PASSWORD:
volumes:
- db-data:/var/lib/mysql

my site_config.json file shows other info:

{
“db_name”: “”,
“db_password”: “”,
“db_type”: “mariadb”,
“encryption_key”: “”
}

is this normal that it can be different? or is my installation at fault?

i used the following input to try and generate the backup:

docker compose -f /git/frappe_docker/pwd.yml exec db sh -c 'exec mariadb-dump –single -transaction -uroot -p “URR4DavK5LgBlu3G” "5e5899d8398b5f7b"’ > /git/testing/backup/database-${date +%Y%m%d%H
%M%S}.sql

when entering it then asks again to type in a password.
i tired both,
admin and “URR4DavK5LgBlu3G”

still comes back with error 1045 access denied

I would also like to know that do i include the quotation marks?
the above post i showed the exact password in my site_config.json file
“URR4DavK5LgBlu3G”
is the quotation marks infact part of the password and db name respectively?

  1. You are using the mariadb root user so you need the mariadb root password, which would be from the docker-compose file. But you actually don’t need it in your command line. If you do put it in, it would be with no space. But it’s easier just to leave the variable as is -p"$MYSQL_ROOT_PASSWORD" and not substitute anything in there. It’s an environment variable your db container will know and be able to access itself when you execute it.

  2. Database name doesn’t need to be in quotes, but you do need the whole thing, including the underscore prefix but no quotation marks surrounding it.

  3. Please redact your site_config.json and compose file quotations, that should never be posted publicly.

hi. thank you. this solved my issues. thanks
now to get the gzip working. is there a guide or examples that shows common gzip functionality?

the same with the date function. it does not work.
the section that is supposed to rename the file to match the dtae and time doesnt work

database-$(date +%Y%m%d_%H%M%S).sql.gz

What is the OS and version of the docker host?

The db container probably has an intentionally limited set of OS commands and even functionality.

This is true, but gzip and date are being run outside of the container context on the host, assuming all of the operators and quote marks are being used properly.

windows 10
docker desktop v 4.38.0

I see. So then the question becomes how limited is docker desktop on windows? Unfortunately, I won’t be able to help with that, but perhaps someone else who is more familiar with docker on windows could help you. Worst case scenario, you could take the sql files and compress them with the GUI to a zip file.

To back up ERPNext/Frappe easily:

  1. Use the built-in bench backup command:
  • SSH into your server, navigate to the ERPNext folder, and run:
cd /path/to/your/frappe-bench
bench backup
  • This creates backups of the database and file store in the sites/{your-site-name}/private/backups folder.
  1. Automate backups (optional):
  • Add a cron job to run the backup daily:
crontab -e
0 0 * * * /usr/local/bin/bench backup --site {your-site-name}


[url="https://acbet.za.com"]Visit My Website[/url]