(self, importKeyPath=None, exportKeyPath=None)
return status.returncode == 0
Initialise the remote repository using borg init
Initialise the remote repository using borg init
Initialise the remote repository using borg init
def initRepository(self, importKeyPath=None, exportKeyPath=None):
        """Initialise the remote repository using borg init"""

        # This can happen if the repository is already initialised
        # and the script is called with the action set as "init"
        if not self.repositoryInitialised():

            os.environ["BORG_PASSPHRASE"] = self.key
            args = [ 'borg', 'init' ]

            # Add encryption type: repository key for now
            args.append('--encryption')
            args.append('keyfile')

            # Add repository path
            args.append(self.repositoryPath)

            status = self.runCommand(args, "Initialising repository")

            if status.returncode != 0:
                raise RuntimeError(status.stderr)

        # When initialising a new repository, make sure the key exists
        # Otherwise, import one
        if not self.repositoryHasKeys() and importKeyPath != None:
            args = [ 'borg', 'key', 'import' ]

            # Add repository path and export path
            args.append(self.repositoryPath)
            args.append(importKeyPath)

            status = self.runCommand(args, "Importing key {0}".format(importKeyPath))

            if status.returncode != 0:
                raise RuntimeError(status.stderr)

            # No need to export the key if we imported one, returns.
            return status.returncode == 0

        # Unless we want to export the key after the initialisation,
        # we can stop here
        if exportKeyPath is None:
            return True

        # If the key path has been specified, export it as well
        args = [ 'borg', 'key', 'export' ]

        # Add repository path and export path
        args.append(self.repositoryPath)
        args.append(exportKeyPath)

        status = self.runCommand(args, "Exporting key in '{0}'".format(exportKeyPath))

        if status.returncode != 0:
            raise RuntimeError(status.stderr)

        return status.returncode == 0
def initRepository ( self , importKeyPath = None , exportKeyPath = None ) : # This can happen if the repository is already initialised # and the script is called with the action set as "init" if not self . repositoryInitialised ( ) : os . environ [ "BORG_PASSPHRASE" ] = self . key args = [ 'borg' , 'init' ] # Add encryption type: repository key for now args . append ( '--encryption' ) args . append ( 'keyfile' ) # Add repository path args . append ( self . repositoryPath ) status = self . runCommand ( args , "Initialising repository" ) if status . returncode != 0 : raise RuntimeError ( status . stderr ) # When initialising a new repository, make sure the key exists # Otherwise, import one if not self . repositoryHasKeys ( ) and importKeyPath != None : args = [ 'borg' , 'key' , 'import' ] # Add repository path and export path args . append ( self . repositoryPath ) args . append ( importKeyPath ) status = self . runCommand ( args , "Importing key {0}" . format ( importKeyPath ) ) if status . returncode != 0 : raise RuntimeError ( status . stderr ) # No need to export the key if we imported one, returns. return status . returncode == 0 # Unless we want to export the key after the initialisation, # we can stop here if exportKeyPath is None : return True # If the key path has been specified, export it as well args = [ 'borg' , 'key' , 'export' ] # Add repository path and export path args . append ( self . repositoryPath ) args . append ( exportKeyPath ) status = self . runCommand ( args , "Exporting key in '{0}'" . format ( exportKeyPath ) ) if status . returncode != 0 : raise RuntimeError ( status . stderr ) return status . returncode == 0