예제 #1
0
    def task_restore(self, localfile, restoreDb=True, withAttachments=True):
        """
        Restore all information not stored in version control from a tarball
        on the invoking users machine.
        """
        restoreDb = str(restoreDb).lower() in ('true', '1', 'yes', 'ok', 'y')

        if restoreDb:
            msg = (
                'All existing files present in the backup will be overwritten and\n'
                'the database dropped and recreated.')
        else:
            msg = (
                'All existing files present in the backup will be overwritten\n'
                '(the database will not be touched).')

        print('')
        if confirm(msg):
            # TODO: Ask for confirmation here
            if restoreDb:
                postgres.dropDb('trac')
                postgres.createDb('trac', 'trac')

            with settings(user=self.serviceUser):
                with utils.tempfile() as temp:
                    files = {
                        'db.dump': temp,
                    }

                    if withAttachments is True:
                        files['attachments'] = 'attachments'

                    archive.restore(files, localfile)
                    if restoreDb:
                        postgres.restoreFromPath('trac', temp)
예제 #2
0
    def task_dump(self, localfile, withAttachments=True):
        """
        Create a tarball containing all information not currently stored in
        version control and download it to the given C{localfile}.

        C{localfile} is a path on your local system.

        Keep it in sync with task_restore.

        For it to work you need your SSH public key added to
        /srv/trac/.ssh/authorized_keys
        """
        with settings(user=self.serviceUser):
            with utils.tempfile() as temp:
                postgres.dumpToPath('trac', temp)

                files = {
                    'db.dump': temp,
                }

                if withAttachments is True:
                    #files['attachments'] = 'attachments'
                    files['trac-attachments'] = 'config/trac-env/files/attachments'

                archive.dump(files, localfile)
예제 #3
0
def restore(spec, localfile):
    with utils.tempfile(uploadFrom=localfile) as tar:
        cmd = [
            '/bin/tar',
            '--extract',
            '--file={}'.format(tar),
            '--verbose',
            '--show-transformed-names',
        ]

        with hide('output'):
            pwd = run('pwd')

        for source, destination in spec.iteritems():
            dirname, basename = os.path.split(destination)
            # Each dirname has to be absolute, otherwise it refers to the
            # previously set --directory.
            dirname = os.path.join(pwd, dirname)
            cmd.extend([
                '\\\n',
                '   --directory {:20s}'.format(dirname),
                '{:15s}'.format(source),
                '--transform',
                quote('s!^{}!{}!'.format(source, basename)),
            ])
        run(' '.join(cmd))
예제 #4
0
    def task_restore(self, localfile, restoreDb=True):
        """
        Restore all information not stored in version control from a tarball
        on the invoking users machine.
        """
        restoreDb = str(restoreDb).lower() in ('true', '1', 'yes', 'ok', 'y')

        if restoreDb:
            msg = (
                'All existing files present in the backup will be overwritten and\n'
                'the database dropped and recreated.'
            )
        else:
            msg = (
                'All existing files present in the backup will be overwritten\n'
                '(the database will not be touched).'
            )

        print ''
        if confirm(msg):
            # TODO: Ask for confirmation here
            if restoreDb:
                postgres.dropDb('trac')
                postgres.createDb('trac', 'trac')

            with settings(user=self.serviceUser):
                with utils.tempfile() as temp:
                    archive.restore({
                        'htpasswd': 'config/htpasswd',
                        'attachments': 'attachments',
                        'db.dump': temp,
                    }, localfile)
                    if restoreDb:
                        postgres.restoreFromPath('trac', temp)
예제 #5
0
 def task_dump(self, localfile):
     """
     Dump codespeed database and download it to the given C{localfile}.
     """
     with settings(user=self.serviceUser):
         with utils.tempfile() as temp:
             run('/usr/bin/sqlite3 ~/data/codespeed.db .dump >{}'.format(temp))
             archive.dump({
                 'db.dump': temp,
             }, localfile)
예제 #6
0
def dump(database, dumpPath, user=None):
    """
    Download a dump of the specified database to C{dumpPath}. This has to be
    executed as a user with enough privileges on the selected database.
    Alternatively a user can be manually provided.
    """
    if user is None:
        user = env.user

    with settings(user=user):
        with utils.tempfile(saveTo=dumpPath) as temp:
            dumpToPath(database, temp)
예제 #7
0
파일: postgres.py 프로젝트: tomprince/braid
def dump(database, dumpPath, user=None):
    """
    Download a dump of the specified database to C{dumpPath}. This has to be
    executed as a user with enough privileges on the selected database.
    Alternatively a user can be manually provided.
    """
    if user is None:
        user = env.user

    with settings(user=user):
        with utils.tempfile(saveTo=dumpPath) as temp:
            dumpToPath(database, temp)
예제 #8
0
    def task_restore(self, localfile):
        """
        Restore codespeed database from the given C{localfile}.
        """
        msg = 'The whole database will be replaced with the backup.'

        if utils.confirm(msg):
            with settings(user=self.serviceUser):
                with utils.tempfile() as temp:
                    archive.restore({
                        'db.dump': temp,
                    }, localfile)
                    run('/bin/rm -f ~/data/codespeed.db')
                    run('/usr/bin/sqlite3 ~/data/codespeed.db ".read {}"'.format(temp))
예제 #9
0
    def task_dump(self, localfile):
        """
        Create a tarball containing all information not currently stored in
        version control and download it to the given C{localfile}.
        """
        with settings(user=self.serviceUser):
            with utils.tempfile() as temp:
                postgres.dumpToPath('trac', temp)

                archive.dump({
                    'htpasswd': 'config/htpasswd',
                    'attachments': 'attachments',
                    'db.dump': temp,
                }, localfile)
예제 #10
0
    def task_dump(self, localfile):
        """
        Create a tarball containing all information not currently stored in
        version control and download it to the given C{localfile}.
        """
        with settings(user=self.serviceUser):
            with utils.tempfile() as temp:
                postgres.dumpToPath('trac', temp)

                archive.dump({
                    'htpasswd': 'config/htpasswd',
                    'attachments': 'attachments',
                    'db.dump': temp,
                }, localfile)
예제 #11
0
파일: fabfile.py 프로젝트: rodrigc/braid
    def task_dump(self, localfile, withAttachments=True):
        """
        Create a tarball containing all information not currently stored in
        version control and download it to the given C{localfile}.
        """
        with settings(user=self.serviceUser):
            with utils.tempfile() as temp:
                postgres.dumpToPath('trac', temp)

                files = {
                    'db.dump': temp,
                }

                if withAttachments is True:
                    files['attachments'] = 'attachments'

                archive.dump(files, localfile)
예제 #12
0
    def task_dump(self, localfile, withAttachments=True):
        """
        Create a tarball containing all information not currently stored in
        version control and download it to the given C{localfile}.
        """
        with settings(user=self.serviceUser):
            with utils.tempfile() as temp:
                postgres.dumpToPath('trac', temp)

                files = {
                    'db.dump': temp,
                }

                if withAttachments is True:
                    files['attachments'] = 'attachments'

                archive.dump(files, localfile)
예제 #13
0
파일: postgres.py 프로젝트: tomprince/braid
def restore(database, dumpPath, user=None, clean=False):
    """
    Upload a local dump and restore it to the named database.

    If no user is specified, set the owner to the current active SSH user.
    This function only works for postgres users which have a corresponding
    system user.

    If clean is specified, the database will be dropped and recreated. The
    database will always be created if it does not exits.
    """
    if user is None:
        user = env.user

    if clean:
        dropDb(database)

    createDb(database, user)

    with settings(user=user):
        with utils.tempfile(uploadFrom=dumpPath) as temp:
            restoreFromPath(database, temp)
예제 #14
0
def restore(database, dumpPath, user=None, clean=False):
    """
    Upload a local dump and restore it to the named database.

    If no user is specified, set the owner to the current active SSH user.
    This function only works for postgres users which have a corresponding
    system user.

    If clean is specified, the database will be dropped and recreated. The
    database will always be created if it does not exits.
    """
    if user is None:
        user = env.user

    if clean:
        dropDb(database)

    createDb(database, user)

    with settings(user=user):
        with utils.tempfile(uploadFrom=dumpPath) as temp:
            restoreFromPath(database, temp)
예제 #15
0
def dump(spec, localfile, exclude=()):
    """
    C{spec} is a dictionary of filenames/dirnames in the tarball to locations
    on the disk from where the contents have to be retrieved.

    Home relative (~/...) file names are not supported by the transformation
    rules as they are converted by the shell before being passed to tar.

    The C{exclude} argument is a list of filename patterns to exclude from the
    dump.
    """

    _, ext = os.path.splitext(localfile)

    with utils.tempfile(suffix=ext) as temp:
        cmd = [
            '/bin/tar',
            '--create',
            '--file={}'.format(temp),
            '--auto-compress',
            '-h',  # Follow symbolic links
            '--verbose',
            '--show-transformed-names',
        ]

        cmd += ['--exclude={}'.format(quote(e)) for e in exclude]

        for destination, source in spec.iteritems():
            cmd.extend([
                '\\\n',
                '   {:30s}'.format(source),
                '--transform',
                quote('s!^{}!{}!'.format(source.lstrip('/'), destination)),
            ])

        run(' '.join(cmd))
        get(temp, localfile)
예제 #16
0
def setDebconfValue(package, question, type, value):
    selections = StringIO(' '.join([package, question, type, value]))
    with tempfile(selections) as controlFile:
        sudo('/usr/bin/debconf-set-selections {}'.format(controlFile))
예제 #17
0
def installEquiv(package, provides, description=None):
    control = _generateControlFile(package, provides, description)
    with tempfile(control) as controlFile, cd('/root'):
        sudo('/usr/bin/equivs-build {}'.format(controlFile))
        sudo('/usr/bin/dpkg -i {}_1.0_all.deb'.format(package))
예제 #18
0
def installEquiv(package, provides, description=None):
    control = _generateControlFile(package, provides, description)
    with tempfile(control) as controlFile, cd('/root'):
        sudo('/usr/bin/equivs-build {}'.format(controlFile))
        sudo('/usr/bin/dpkg -i {}_1.0_all.deb'.format(package))
예제 #19
0
def setDebconfValue(package, question, type, value):
    selections = StringIO(' '.join([package, question, type, value]))
    with tempfile(selections) as controlFile:
        sudo('/usr/bin/debconf-set-selections {}'.format(controlFile))