mirror of
https://github.com/frappe/frappe_docker.git
synced 2025-02-03 12:38:29 +00:00
fix: backup and restore
new command FORCE=1 error fixed only push backups if exists prepare and process db restore
This commit is contained in:
parent
3a6f7e1934
commit
4e7b7690ee
@ -29,36 +29,27 @@ def main():
|
|||||||
|
|
||||||
site_config = get_site_config(site_name)
|
site_config = get_site_config(site_name)
|
||||||
|
|
||||||
# update User's host to '%' required to connect from any container
|
mysql_command = 'mysql -h{db_host} -u{mariadb_root_username} -p{mariadb_root_password} -e '.format(
|
||||||
command = 'mysql -h{db_host} -u{mariadb_root_username} -p{mariadb_root_password} -e '.format(
|
|
||||||
db_host=config.get('db_host'),
|
db_host=config.get('db_host'),
|
||||||
mariadb_root_username=mariadb_root_username,
|
mariadb_root_username=mariadb_root_username,
|
||||||
mariadb_root_password=mariadb_root_password
|
mariadb_root_password=mariadb_root_password
|
||||||
)
|
)
|
||||||
command += "\"UPDATE mysql.user SET Host = '%' where User = '{db_name}'; FLUSH PRIVILEGES;\"".format(
|
|
||||||
|
# update User's host to '%' required to connect from any container
|
||||||
|
command = mysql_command + "\"UPDATE mysql.user SET Host = '%' where User = '{db_name}'; FLUSH PRIVILEGES;\"".format(
|
||||||
db_name=site_config.get('db_name')
|
db_name=site_config.get('db_name')
|
||||||
)
|
)
|
||||||
os.system(command)
|
os.system(command)
|
||||||
|
|
||||||
# Set db password
|
# Set db password
|
||||||
command = 'mysql -h{db_host} -u{mariadb_root_username} -p{mariadb_root_password} -e '.format(
|
command = mysql_command + "\"UPDATE mysql.user SET authentication_string = PASSWORD('{db_password}') WHERE User = \'{db_name}\' AND Host = \'%\';\"".format(
|
||||||
db_host=config.get('db_host'),
|
|
||||||
mariadb_root_username=mariadb_root_username,
|
|
||||||
mariadb_root_password=mariadb_root_password
|
|
||||||
)
|
|
||||||
command += "\"SET PASSWORD FOR '{db_name}'@'%' = PASSWORD('{db_password}'); FLUSH PRIVILEGES;\"".format(
|
|
||||||
db_name=site_config.get('db_name'),
|
db_name=site_config.get('db_name'),
|
||||||
db_password=site_config.get('db_password')
|
db_password=site_config.get('db_password')
|
||||||
)
|
)
|
||||||
os.system(command)
|
os.system(command)
|
||||||
|
|
||||||
# Grant permission to database
|
# Grant permission to database
|
||||||
command = 'mysql -h{db_host} -u{mariadb_root_username} -p{mariadb_root_password} -e '.format(
|
command = mysql_command + "\"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;\"".format(
|
||||||
db_host=config.get('db_host'),
|
|
||||||
mariadb_root_username=mariadb_root_username,
|
|
||||||
mariadb_root_password=mariadb_root_password
|
|
||||||
)
|
|
||||||
command += "\"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;\"".format(
|
|
||||||
db_name=site_config.get('db_name')
|
db_name=site_config.get('db_name')
|
||||||
)
|
)
|
||||||
os.system(command)
|
os.system(command)
|
||||||
|
@ -92,6 +92,7 @@ def delete_old_backups(limit, bucket, site_name):
|
|||||||
backup_limit = int(limit)
|
backup_limit = int(limit)
|
||||||
check_environment_variables()
|
check_environment_variables()
|
||||||
bucket_dir = os.environ.get('BUCKET_DIR')
|
bucket_dir = os.environ.get('BUCKET_DIR')
|
||||||
|
oldest_backup_date = None
|
||||||
|
|
||||||
s3 = boto3.resource(
|
s3 = boto3.resource(
|
||||||
's3',
|
's3',
|
||||||
@ -123,7 +124,8 @@ def delete_old_backups(limit, bucket, site_name):
|
|||||||
print(error)
|
print(error)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
oldest_backup_date = min(all_backup_dates)
|
if len(all_backup_dates) > 0:
|
||||||
|
oldest_backup_date = min(all_backup_dates)
|
||||||
|
|
||||||
if len(all_backups) / 3 > backup_limit:
|
if len(all_backups) / 3 > backup_limit:
|
||||||
oldest_backup = None
|
oldest_backup = None
|
||||||
|
@ -8,7 +8,7 @@ import boto3
|
|||||||
from push_backup import DATE_FORMAT, check_environment_variables
|
from push_backup import DATE_FORMAT, check_environment_variables
|
||||||
from frappe.utils import get_sites, random_string
|
from frappe.utils import get_sites, random_string
|
||||||
from frappe.commands.site import _new_site
|
from frappe.commands.site import _new_site
|
||||||
from frappe.installer import make_conf, get_conf_params
|
from frappe.installer import make_conf, get_conf_params, make_site_dirs
|
||||||
from check_connection import get_site_config, get_config
|
from check_connection import get_site_config, get_config
|
||||||
|
|
||||||
def list_directories(path):
|
def list_directories(path):
|
||||||
@ -44,8 +44,8 @@ def restore_database(files_base, site):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
db_root_user = os.environ.get("DB_ROOT_USER", 'root')
|
db_root_user = os.environ.get("DB_ROOT_USER", 'root')
|
||||||
# restore database
|
|
||||||
|
|
||||||
|
# restore database
|
||||||
database_file = files_base + '-database.sql.gz'
|
database_file = files_base + '-database.sql.gz'
|
||||||
decompress_db(files_base, site)
|
decompress_db(files_base, site)
|
||||||
config = get_config()
|
config = get_config()
|
||||||
@ -58,6 +58,12 @@ def restore_database(files_base, site):
|
|||||||
db_password=db_root_password
|
db_password=db_root_password
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# drop db if exists for clean restore
|
||||||
|
drop_database = mysql_command + "\"DROP DATABASE IF EXISTS \`{db_name}\`;\"".format(
|
||||||
|
db_name=site_config.get('db_name')
|
||||||
|
)
|
||||||
|
os.system(drop_database)
|
||||||
|
|
||||||
# create db
|
# create db
|
||||||
create_database = mysql_command + "\"CREATE DATABASE IF NOT EXISTS \`{db_name}\`;\"".format(
|
create_database = mysql_command + "\"CREATE DATABASE IF NOT EXISTS \`{db_name}\`;\"".format(
|
||||||
db_name=site_config.get('db_name')
|
db_name=site_config.get('db_name')
|
||||||
@ -71,6 +77,13 @@ def restore_database(files_base, site):
|
|||||||
)
|
)
|
||||||
os.system(create_user)
|
os.system(create_user)
|
||||||
|
|
||||||
|
# create user password
|
||||||
|
set_user_password = mysql_command + "\"UPDATE mysql.user SET authentication_string = PASSWORD('{db_password}') WHERE User = \'{db_name}\' AND Host = \'%\';\"".format(
|
||||||
|
db_name=site_config.get('db_name'),
|
||||||
|
db_password=site_config.get('db_password')
|
||||||
|
)
|
||||||
|
os.system(set_user_password)
|
||||||
|
|
||||||
# grant db privileges to user
|
# grant db privileges to user
|
||||||
grant_privileges = mysql_command + "\"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;\"".format(
|
grant_privileges = mysql_command + "\"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;\"".format(
|
||||||
db_name=site_config.get('db_name')
|
db_name=site_config.get('db_name')
|
||||||
@ -162,9 +175,9 @@ def main():
|
|||||||
frappe.local.site_path = os.getcwd() + '/' + site
|
frappe.local.site_path = os.getcwd() + '/' + site
|
||||||
make_conf(
|
make_conf(
|
||||||
db_name=site_config.get('db_name'),
|
db_name=site_config.get('db_name'),
|
||||||
db_password=site_config.get('db_name'),
|
db_password=site_config.get('db_password'),
|
||||||
)
|
)
|
||||||
|
make_site_dirs()
|
||||||
restore_database(files_base, site)
|
restore_database(files_base, site)
|
||||||
restore_private_files(files_base)
|
restore_private_files(files_base)
|
||||||
restore_files(files_base)
|
restore_files(files_base)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user