Backup and Restore procedure

I had been trying to search for some kind of documentation for taking backups from remote and doing a complete restore on the local desktop. After searching the whole of discussion forum and getting stuck at few places, I was able to download the backup from the remote site on the local machine and do a restore on the local desktop. I will share the steps that I followed so that it can be useful for other people also:

Backup and Restore

  1. Download the latest backup from the Setup:

  1. This will get saved on your local desktop in the downloads folder.

  2. Copy this file under this folder:

The site-name is the name of the site on your local desktop.

  1. Unzip the file using the following commands:

umag@epoch~$ cd frappe-bench/sites/site-name/public/files
umag@epoch~/frappe-bench/sites/site-name/public/files$ gunzip 20160602_78570815_database.sql.gz
umag@epoch~/frappe-bench/sites/site-name/public/files$ cd
umag@epoch:~$ pwd
umag@epoch~$ cd frappe-bench
umag@epoch~/frappe-bench$ bench - - site site-name - - force restore $PWD/sites/site-name/public/files/ 20160602_78570815_database.sql

It will ask for the MySQL root password. Once you enter the password, it will get restored.

Though, I was able to restore the files on the local machine, it was giving some operational error of table not found while logging into the localhost. So, I searched the web again and realized that I had to do a bench migrate as well. So, I ran this command in the command prompt.

umag@epoch:~frappe-bench$ bench - -site site-name migrate

Once this was done, I was able to view the remote databases on my local machine.


Hi, there’s existing documentation for restoring a database :


Are you using Oracle Virtual Box for the local machine? If yes can you give details on step 2. I could not find how to do that step

Hi Ron,

I had used the Ubuntu desktop and had copied the file from the Files explorer. I am not using Oracle Virtual Box.

@Ron_Taylor one of easy way if you’re using VM is by using ftp client to copy files

Bitvise is a good ssh program with built in ftp, saves a step during the restore process

Can you explain how for me? I am Totally rubbish for this kind of thing

  1. Connect your ftp client to VM e.g.
  2. Locate backup files under ~/frappe-bench/sites/[your-site]/private/backups

get “winSCP”

use “sftp” proto
add hostname “localhost”
port “3022”

PS i know its old question, but :slight_smile:

1 Like

Thank you, you saved me a lot of time

Can someone tell me what the MySQL root password is when using the Oracle VM? Been stuck on that for a while now…

frappe is the default

Got it. Thanks! Would you also happen to know what to do when this happens when running the “bench restore” command?
“Exception: Database 46459e8459d14de1 already exists”

I am guessing that you will need to drop the database before executing the restore.

Welcome to ERPNext and thanks ptsiampas

Check this to do that Database already exists

Yeah, I got that, I was replying to the guy above my comment. Figured it was a pretty simple thing to do from MySQL :slight_smile: unless you have zero experience with databases then, well time to read stuff.

1 Like

can Mack video for this please

Want to have Downloaded Backup of to be restored to

Please Guide.

I have a function in a bash shell script to unwrap a backup package, change the site name from, for example, to then repackage it with the appropriate new name.

function repackageWithCorrectedSiteName() {
  echo -e "       The backup is from a different ERPNext site.";
  rm -fr *;
  tar zxvf ${BACKUP_DIR}/${BACKUP_FILE_FULL_NAME} > /dev/null;
  echo -e "       Will rename all backup files ...${pFAINT_BLUE}";
  gunzip ${BACKUP_FILE_NAME}-database.sql.gz >/dev/null;
  # ls -la ${BACKUP_FILE_NAME}-*;

  declare OLD_FILE="";
  declare NEW_FILE="";

  echo "       - '${OLD_FILE}' becomes '${NEW_FILE}'."
  mv ${OLD_FILE} ${NEW_FILE};
  # ls -la;
  gzip ${NEW_FILE};

  echo "       - '${OLD_FILE}' becomes '${NEW_FILE}'."
  mv ${OLD_FILE} ${NEW_FILE};

  echo "       - '${OLD_FILE}' becomes '${NEW_FILE}'."
  mv ${OLD_FILE} ${NEW_FILE};

  echo "       - '${OLD_FILE}' becomes '${NEW_FILE}'."
  mv ${OLD_FILE} ${NEW_FILE};

  echo -e "${pDFLT}    - patch site name with sed.  -->  '${NEW_FILE}' from '${OLD_SITE_URL//_/.}' to '${ERPNEXT_SITE_URL}' ";

  sed -i "s/${OLD_SITE_URL//_/.}/${ERPNEXT_SITE_URL}/g" ${NEW_FILE};
  # jq -r . ${NEW_FILE};


  echo -e "${pDFLT}    - Creating new package from repackaged contents of '${BACKUP_FILE_FULL_NAME}'."
           tar zcvf ${BACKUP_DIR}/${NEW_FILE} ${NEW_FILE%".tgz"}-* >/dev/null;

  echo -e "        Resulting file is -"
  echo -e "         - ${BACKUP_DIR}/${NEW_FILE}";

  echo -e "    - Writing new package file name into file name holder : '${BACKUP_FILE_NAME_HOLDER}'."


When you supply all the right variables content and run it the end result output looks like this:

       The backup is from a different ERPNext site.
       Will rename all backup files ...
       - '20240618_071313-desaitech_erpnext_com-database.sql' becomes '20240618_071313-erp_desaitechindia_com-database.sql'.
       - '20240618_071313-desaitech_erpnext_com-files.tar' becomes '20240618_071313-erp_desaitechindia_com-files.tar'.
       - '20240618_071313-desaitech_erpnext_com-private-files.tar' becomes '20240618_071313-erp_desaitechindia_com-private-files.tar'.
       - '20240618_071313-desaitech_erpnext_com-site_config_backup.json' becomes '20240618_071313-erp_desaitechindia_com-site_config_backup.json'.
    - patch site name with sed.  -->  '20240618_071313-erp_desaitechindia_com-site_config_backup.json' from '' to '' 
    - Creating new package from repackaged contents of '20240618_071313-desaitech_erpnext_com.tgz'.
        Resulting file is -
         - /home/adm/frappe-bench-DESAI/BKP/20240618_071313-erp_desaitechindia_com.tgz
    - Writing new package file name into file name holder : '/home/adm/frappe-bench-DESAI/BKP/BACKUP.txt'.

You may want to study the Ubuntu Linux commands:

  • gunzip - extract from zip package
  • gzip - recreate zip package
  • mv - change a file’s name &/or location
  • tar - create/extract archive file
  • sed - search and replace text within file