77
88from modules .module import MtcModule
99from mypylib .mypylib import color_print , ip2int , run_as_root , parse , MyPyClass
10+ from mytonctrl .utils import get_current_user , pop_user_from_args
1011from mytoninstaller .config import get_own_ip
1112
1213
@@ -28,19 +29,22 @@ def create_tmp_ton_dir(self):
2829 return dir_name
2930
3031 @staticmethod
31- def run_create_backup (args ):
32+ def run_create_backup (args , user : str = None ):
33+ if user is None :
34+ user = get_current_user ()
3235 backup_script_path = pkg_resources .resource_filename ('mytonctrl' , 'scripts/create_backup.sh' )
33- return subprocess .run (["bash" , backup_script_path ] + args , timeout = 5 )
36+ return subprocess .run (["bash" , backup_script_path , "-u" , user ] + args , timeout = 5 )
3437
3538 def create_backup (self , args ):
36- if len (args ) > 1 :
37- color_print ("{red}Bad args. Usage:{endc} create_backup [filename]" )
39+ if len (args ) > 3 :
40+ color_print ("{red}Bad args. Usage:{endc} create_backup [filename] [-u <user>] " )
3841 return
3942 tmp_dir = self .create_tmp_ton_dir ()
4043 command_args = ["-m" , self .ton .local .buffer .my_work_dir , "-t" , tmp_dir ]
44+ user = pop_user_from_args (args )
4145 if len (args ) == 1 :
4246 command_args += ["-d" , args [0 ]]
43- process = self .run_create_backup (command_args )
47+ process = self .run_create_backup (command_args , user = user )
4448
4549 if process .returncode == 0 :
4650 color_print ("create_backup - {green}OK{endc}" )
@@ -51,14 +55,17 @@ def create_backup(self, args):
5155 # end define
5256
5357 @staticmethod
54- def run_restore_backup (args ):
58+ def run_restore_backup (args , user : str = None ):
59+ if user is None :
60+ user = get_current_user ()
5561 restore_script_path = pkg_resources .resource_filename ('mytonctrl' , 'scripts/restore_backup.sh' )
56- return run_as_root (["bash" , restore_script_path ] + args )
62+ return run_as_root (["bash" , restore_script_path , "-u" , user ] + args )
5763
5864 def restore_backup (self , args ):
59- if len (args ) == 0 or len (args ) > 3 :
60- color_print ("{red}Bad args. Usage:{endc} restore_backup <filename> [-y] [--skip-create-backup]" )
65+ if len (args ) == 0 or len (args ) > 5 :
66+ color_print ("{red}Bad args. Usage:{endc} restore_backup <filename> [-y] [--skip-create-backup] [-u <user>] " )
6167 return
68+ user = pop_user_from_args (args )
6269 if '-y' not in args :
6370 res = input (
6471 f'This action will overwrite existing configuration with contents of backup archive, please make sure that donor node is not in operation prior to this action. Proceed [y/n]' )
@@ -79,7 +86,7 @@ def restore_backup(self, args):
7986 ip = str (ip2int (get_own_ip ()))
8087 command_args = ["-m" , self .ton .local .buffer .my_work_dir , "-n" , args [0 ], "-i" , ip ]
8188
82- if self .run_restore_backup (command_args ) == 0 :
89+ if self .run_restore_backup (command_args , user = user ) == 0 :
8390 self .ton .local .load_db ()
8491 if self .ton .using_validator ():
8592 from modules .btc_teleport import BtcTeleportModule
0 commit comments