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:
This will get saved on your local desktop in the downloads folder.
Copy this file under this folder:
frappe-bench/sites/site-name/public/files
The site-name is the name of the site on your local desktop.
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
/home/umag
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.
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”
Yeah, I got that, I was replying to the guy above my comment. Figured it was a pretty simple thing to do from MySQL unless you have zero experience with databases then, well time to read stuff.
I have a function in a bash shell script to unwrap a backup package, change the site name from, for example, desaitech.erpnext.com to erp.desaitechindia.com then repackage it with the appropriate new name.
function repackageWithCorrectedSiteName() {
echo -e " The backup is from a different ERPNext site.";
declare BACKUP_FILE_NAME=${BACKUP_FILE_FULL_NAME%".tgz"}
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="";
OLD_FILE="${BACKUP_FILE_NAME}-database.sql";
NEW_FILE=${OLD_FILE/${BACKUP_FILE_SITE_NAME}/"${SITE_ALIAS}"};
echo " - '${OLD_FILE}' becomes '${NEW_FILE}'."
mv ${OLD_FILE} ${NEW_FILE};
# ls -la;
gzip ${NEW_FILE};
OLD_FILE="${BACKUP_FILE_NAME}-files.tar";
NEW_FILE=${OLD_FILE/${BACKUP_FILE_SITE_NAME}/"${SITE_ALIAS}"};
echo " - '${OLD_FILE}' becomes '${NEW_FILE}'."
mv ${OLD_FILE} ${NEW_FILE};
OLD_FILE="${BACKUP_FILE_NAME}-private-files.tar";
NEW_FILE=${OLD_FILE/${BACKUP_FILE_SITE_NAME}/"${SITE_ALIAS}"};
echo " - '${OLD_FILE}' becomes '${NEW_FILE}'."
mv ${OLD_FILE} ${NEW_FILE};
OLD_FILE="${BACKUP_FILE_NAME}-site_config_backup.json";
NEW_FILE=${OLD_FILE/${BACKUP_FILE_SITE_NAME}/"${SITE_ALIAS}"};
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};
OLD_FILE="${BACKUP_FILE_NAME}.tgz";
NEW_FILE=${OLD_FILE/${BACKUP_FILE_SITE_NAME}/"${SITE_ALIAS}"};
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}'."
echo -e "${NEW_FILE}" > ${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 'erp.logichem.solutions' to 'erp.iridium.blue'
- 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'.