Backup & Restore

Hi,

I’m using v5. Is there clear steps/documentation on how to backup erpnext database and restore it on local/another server machine?

How to automate backup periodically? Anybody could help?

Thanks

Following command takes backup in v5

~/frappe-bench$ bench backup 

for more

~/frappe-bench$ bench --help
Usage:  [OPTIONS] COMMAND [ARGS]...

  Bench manager for Frappe

Options:
  --help  Show this message and exit.

Commands:
  backup               backup site
  backup-all-sites     backup all sites
  config               change bench configuration
  get-app              clone an app from the internet and set it up...
  init                 Create a new bench
  migrate-3to4         Migrate from ERPNext v3.x
  new-app              start a new app
  new-site             Create a new site in the bench
  patch
  prime-wheel-cache    Update wheel cache
  release              Release app (internal to the Frappe team)
  restart              Restart supervisor processes
  retry-upgrade
  set-default-site     Set default site for bench
  set-mariadb-host     Set MariaDB host for bench
  set-nginx-port       Set nginx port for site
  set-ssl-certificate  Set ssl certificate path for site
  set-ssl-key          Set ssl certificate private key path for site
  set-url-root         Set url root for site
  setup                Setup bench
  shell
  start                Start Frappe development processes
  switch-to-develop    Switch frappe and erpnext to develop branch
  switch-to-master     Switch frappe and erpnext to master branch
  switch-to-v4         Switch frappe and erpnext to v4 branch
  update               Update bench

Framework commands:

  add-system-manager          Add a new system manager to a site
  backup                      Backup
  build                       Minify + concatenate JS and CSS files, build...
  build-docs                  Build docs from /src to /www folder in app
  build-message-files         Build message files for translation
  build-website               Sync statics and clear cache
  celery                      Run a celery command
  clear-cache                 Clear cache, doctype cache and defaults
  clear-website-cache         Clear website cache
  console                     Start ipython console for a site
  destroy-all-sessions        Clear sessions of all users (logs them out)
  disable-scheduler           Disable scheduler
  doctor                      Get untranslated strings for lang.
  drop-site
  dump-queue-status           Dump detailed diagnostic infomation for task...
  enable-scheduler            Enable scheduler
  execute                     execute a function
  export-csv                  Dump DocType as csv
  export-doc                  Export a single document to csv
  export-fixtures             export fixtures
  export-json                 Export doclist as json to the given path, use...
  get-untranslated            Get untranslated strings for language
  import-doc                  Import (insert/update) doclist.
  install-app                 Install a new app to site
  make-app
  migrate                     Run patches, sync schema and rebuild...
  mysql                       Start Mariadb console for a site
  new-site                    Install a new site
  purge-all-tasks             Purge any pending periodic tasks of 'all'...
  reinstall                   Reinstall site ie.
  reload-doc                  Reload schema for a DocType
  remove-from-installed-apps
  request                     Run a request as an admin
  reset-perms                 Reset permissions for all doctypes
  restore                     Restore site database from an sql file
  run-patch                   Run a particular patch
  run-tests                   Run tests
  serve                       Start development web server
  set-admin-password          Set Administrator password for a site
  setup-docs                  Setup docs in target folder of target app
  sync-www                    Sync files from static pages from www...
  trigger-scheduler-event     Trigger a scheduler event
  update-translations         Update translated strings
  use
  watch                       Watch and concatenate JS and CSS files as and...

Issue: “Setup > System > Download Backup” is showing “Backup Manager”

8 Likes

@revant_one, Would you please to share step by step… how to use the commands to backup one site then restore it on same site or to another site/machine?

Tks a lot

change to bench directory

erpnext@server:~$ cd frappe-bench/
erpnext@server:~/frappe-bench$ 

use command

erpnext@server:~/frappe-bench$ bench backup

or command

erpnext@server:~/frappe-bench$ bench backup-all-sites

your database backups will be in ~/frappe-bench/sites/[sitename]/private/backups/
check out for the most recent backup with current time, there may be backups there already.

Now take backups of files

erpnext@server:~/frappe-bench/sites/[sitename]/public$ tar cvf ~/[sitename]-files.tar files

2 Backup files:

  1. Database backup
  2. Files backup

Setup bench on other machine where you want to restore.
Extract files in appropriate site’s sub directory ~/frappe-bench/sites/[sitename]/public and restore database backup.

erpnext@other-server:~/frappe-bench$ bench restore SQL_FILE_PATH

for more info

$ bench restore --help
18 Likes

Hi @revant_one,

Thx a lot for your help.

I’m not linux user so I need to careful to do this.
From your description, bench provide backup and restore command…my question-Do we still need to do mysqldump after bench backup? Then restore again using bench restore?

Is Bench backup and restore different with mysqldump?

Thanks again

No need to use mysqldump when bench backup and restore is working.
I just refer the mysqldump command if bench is not available or not working and I need to take backup of any database.

No need to use both bench and mysqldump.
Only bench is enough for backup and restore.

Revant

1 Like

I’ve just restored backup database to a new site on different machine. I used --db-name option with new database name. Without --db-name option, got ‘database already exist’

I opened browser and it’s looked the erpnext site still pointing to original db name.

  1. How to point the site to new db name?
  2. Or how to restore backup-db and replace original db?

Anybody can help please to give some hints?

Thanks a lot

I thought there should be two files for this. Why do I only get the database backup and not the file backup?

following command will also create a backup with files.

$ bench backup --with-files
3 Likes

Thanks. Is there a way to do selective backup? Like for example just for a specific module or doctype only?

bench backup and restore helps to go back to a state at which backup was taken or move site from one server to another.
Also set Third Party Backups so you can relax!

You can take backups for selective sites with command

$ bench --site <sitename> backup --with-files

for Importing / Exporting Data for selective doctypes use Data Import Tool.
Data Import Tool is NOT Backup

17 Likes

I haven’t tried this but it should work:
If you have already uploaded your new db into Maria and called it dave, Then edit your site_config.json file (located in frappe-bench/sites/site1.local) and change the field:
“db_name”: “1bdxxxxxx22” ,
To
“db_name”: “dave”,
Should be able to keep pass the same.
Otherwise some simple SQL will achieve the same thing.
SHOW DATABASE
choose your DB
Drop all db 1bdxxxxxx22 tables
Import all your new tables into 1bdxxxxxx22db.
Don’t need to touch the config file just restart bench and reload browser. Done.

3 Likes