#NEWLINE# def backup_data( path , keyname ) : #NEWLINE# #INDENT# " Backup Zookeeper data to path.\n\n  Args:\n    path: A str, the name of the backup file to be created.\n    keyname: A string containing the deployment's keyname.\n  Raises:\n    BRException if unable to find any ZooKeeper machines.\n  " #NEWLINE# logging . info ( 'Starting new zk backup.' ) #NEWLINE# running = ( subprocess . call ( [ 'service' , CONTROLLER_SERVICE , 'status' ] ) == 0 ) #NEWLINE# if ( not running ) : #NEWLINE# #INDENT# logging . error ( 'Please start AppScale before backing up ZooKeeper.' ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# zk_ips = appscale_info . get_zk_node_ips ( ) #NEWLINE# if ( not zk_ips ) : #NEWLINE# #INDENT# raise BRException ( 'Unable to find any ZooKeeper machines.' ) #NEWLINE# #UNINDENT# zk_ip = zk_ips [ 0 ] #NEWLINE# timestamp = int ( time . time ( ) ) #NEWLINE# backup_file = '{}/zk_backup_{}.tar.gz' . format ( BACKUP_DIR_LOCATION , timestamp ) #NEWLINE# try : #NEWLINE# #INDENT# utils . ssh ( zk_ip , keyname , 'monit stop -g zookeeper' ) #NEWLINE# utils . ssh ( zk_ip , keyname , 'tar czf {} -C {} .' . format ( backup_file , ZK_DATA_DIR ) ) #NEWLINE# utils . scp_from ( zk_ip , keyname , backup_file , path ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# utils . ssh ( zk_ip , keyname , 'rm -f {}' . format ( backup_file ) ) #NEWLINE# utils . ssh ( zk_ip , keyname , 'monit start -g zookeeper' )