PyHardLinkBackup
431054
def cli(ctx):
    """"""
    click.secho("\n v%s\n" % .__version__, bg="blue", fg="white", bold=True)
836692
def backup(app):
    """"""
    dump_path = dump_database(app)

    config = PsiturkConfig()
    config.load_config()

    conn = boto.connect_s3(
        config.get('AWS Access', 'aws_access_key_id'),
        config.get('AWS Access', 'aws_secret_access_key'),
    )

    bucket = conn.create_bucket(
        app,
        location=boto.s3.connection.Location.DEFAULT
    )

    k = boto.s3.key.Key(bucket)
    k.key = 'database.dump'
    k.set_contents_from_filename(dump_path)
    url = k.generate_url(expires_in=0, query_auth=False)

    log("The database backup URL is...")
    print(url)
1287259
def backup_db():
    
    if not os.path.exists('backups'):
        os.makedirs('backups')
    local('python manage.py dump_database | gzip > backups/' + _sql_paths('local', datetime.now()))
350162
function fileLinkCopy( $srcPath, $dstPath, $symLink )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileLinkCopy( '$srcPath', '$dstPath' )", __METHOD__ );

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
        eZFileHandler::linkCopy( $srcPath, $dstPath, $symLink );
        eZDebug::accumulatorStop( 'dbfile' );
    }
273881
def _rm_dr_link(self, rec):
        # type: (dr.DirectoryRecord) -> int
        '''
        
        '''
        if not rec.is_file():
            raise pycdlibexception.PyCdlibInvalidInput('Cannot remove a directory with rm_hard_link (try rm_directory instead)')

        num_bytes_to_remove = 0

        logical_block_size = rec.vd.logical_block_size()

        done = False
        while not done:
            num_bytes_to_remove += self._remove_child_from_dr(rec,
                                                              rec.index_in_parent,
                                                              logical_block_size)

            if rec.inode is not None:
                found_index = None
                for index, link in enumerate(rec.inode.linked_records):
                    if id(link) == id(rec):
                        found_index = index
                        break
                else:
                    # This should never happen
                    raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')

                del rec.inode.linked_records[found_index]

                # We only remove the size of the child from the ISO if there are no
                # other references to this file on the ISO.
                if not rec.inode.linked_records:
                    found_index = None
                    for index, ino in enumerate(self.inodes):
                        if id(ino) == id(rec.inode):
                            found_index = index
                            break
                    else:
                        # This should never happen
                        raise pycdlibexception.PyCdlibInternalError('Could not find inode corresponding to record')
                    del self.inodes[found_index]

                    num_bytes_to_remove += rec.get_data_length()

            if rec.data_continuation is not None:
                rec = rec.data_continuation
            else:
                done = True

        return num_bytes_to_remove
649446
def backup_all(args):
    '''
    
    '''
    username = None
    password = None
    auth = args.get('--auth')
    path = args.get('--path')
    s3 = args.get('--upload_s3')
    glacier = args.get('--upload_glacier')
    dropbox = args.get('--upload_dropbox')
    swift = args.get('--upload_swift')
    encrypt = args.get('--encrypt') or 'Y'

    if (ADMIN_USER and ADMIN_PASSWORD):
        username = ADMIN_USER
        password = ADMIN_PASSWORD

    if not path:
        path = os.getcwd()
    if path and not os.path.isdir(path):
        raise SystemExit(_error_codes.get(105))

    if auth:
        query = 'mongodump -u {username} -p {password} '
    else:
        query = 'mongodump '
    if path:
        query += '-o {path}/dump'

    local(query.format(username=username,
                       password=password,
                       path=path))

    compress_file = compress_folder_dump(
        normalize_path(path) + 'dump', normalize_path(path))

    shutil.rmtree(normalize_path(path) + 'dump')

    optional_actions(encrypt, path, compress_file, s3=s3, glacier=glacier,
                     dropbox=dropbox, swift=swift)
1114502
def restore(self):
        
        if os.path.exists(self.backup_path):
            for file in glob.glob(self.backup_path + "/*"):
                shutil.copy(file, self.path)
28355
def upload_ssh_key(rollback=False):
    
    auth_keys = '/home/%s/.ssh/authorized_keys'% env.user
    if not rollback:
        local_user = getpass.getuser()
        host = socket.gethostname()
        u = '@'.join([local_user,host])
        u = 'ssh-key-uploaded-%s'% u
        if not env.overwrite and server_state(u): return
        if not exists('.ssh'):
            run('mkdir .ssh')
           
        #determine local .ssh dir
        home = os.path.expanduser('~')
        ssh_key = None
        upload_key = True
        ssh_dsa = os.path.join(home,'.ssh/id_dsa.pub')
        ssh_rsa =  os.path.join(home,'.ssh/id_rsa.pub')
        if env.key_filename and env.INTERACTIVE:
                upload_key = confirm('Would you like to upload your personal key in addition to %s'% str(env.key_filename), default=True)
        if upload_key:  
            if os.path.exists(ssh_dsa):
                ssh_key = ssh_dsa
            elif os.path.exists(ssh_rsa):
                ssh_key = ssh_rsa
    
        if ssh_key:
            ssh_file = open(ssh_key,'r').read()
            
            if exists(auth_keys):
                _backup_file(auth_keys)
            if env.verbosity:
                print env.host, "UPLOADING SSH KEY"
            append(auth_keys,ssh_file) #append prevents uploading twice
            set_server_state(u)
        return
    else:
        if exists(auth_keys+'.wovenbak'):
            _restore_file('/home/%s/.ssh/authorized_keys'% env.user)
        else: #no pre-existing keys remove the .ssh directory
            sudo('rm -rf /home/%s/.ssh')
        return
1337047
def rsync(local_path, remote_path, exclude=None, extra_opts=None):
    """"""
    if not local_path.endswith('/'):
        local_path += '/'
    exclude = exclude or []
    exclude.extend(['*.egg-info', '*.pyc', '.git', '.gitignore',
                    '.gitmodules', '/build/', '/dist/'])
    with hide('running'):
        run("mkdir -p '{}'".format(remote_path))
        return rsync_project(
            remote_path, local_path, delete=True,
            extra_opts='-i --omit-dir-times -FF ' +
                       (extra_opts if extra_opts else ''),
            ssh_opts='-o StrictHostKeyChecking=no',
            exclude=exclude)
173819
def prepend_to_file(path, data, bufsize=1<<15):
    
    # Backup the file #
    backupname = path + os.extsep + 'bak'
    # Remove previous backup if it exists #
    try: os.unlink(backupname)
    except OSError: pass
    os.rename(path, backupname)
    # Open input/output files,  note: outputfile's permissions lost #
    with open(backupname) as inputfile:
        with open(path, 'w') as outputfile:
            outputfile.write(data)
            buf = inputfile.read(bufsize)
            while buf:
                outputfile.write(buf)
                buf = inputfile.read(bufsize)
    # Remove backup on success #
    os.remove(backupname)
46261
def _download_py2(link, path, __hdr__):
    """"""
    try:
        req = urllib2.Request(link, headers=__hdr__)
        u = urllib2.urlopen(req)
    except Exception as e:
        raise Exception(' Download failed with the error:\n{}'.format(e))

    with open(path, 'wb') as outf:
        for l in u:
            outf.write(l)
    u.close()
377586
def dump_database(id):
    """"""
    log("Generating a backup of the database on Heroku...")

    dump_filename = "data.dump"
    data_directory = "data"
    dump_dir = os.path.join(data_directory, id)
    if not os.path.exists(dump_dir):
        os.makedirs(dump_dir)

    subprocess.call("heroku pg:backups capture --app " + id, shell=True)

    backup_url = subprocess.check_output(
        "heroku pg:backups public-url --app " + id, shell=True)
    backup_url = backup_url.replace('"', '').rstrip()
    backup_url = re.search("https:.*", backup_url).group(0)
    print(backup_url)

    log("Downloading the backup...")
    dump_path = os.path.join(dump_dir, dump_filename)
    with open(dump_path, 'wb') as file:
        subprocess.call(['curl', '-o', dump_path, backup_url], stdout=file)

    return dump_path
968197
def backUpDB() :
    """"""
    st = time.ctime().replace(' ', '_')
    fn = conf.pyGeno_RABA_DBFILE.replace('.db', '_%s-bck.db' % st)
    shutil.copy2(conf.pyGeno_RABA_DBFILE, fn)

    return fn
703241
def backup_minion(path, bkroot):
    '''
    
    '''
    dname, bname = os.path.split(path)
    if salt.utils.platform.is_windows():
        src_dir = dname.replace(':', '_')
    else:
        src_dir = dname[1:]
    if not salt.utils.platform.is_windows():
        fstat = os.stat(path)
    msecs = six.text_type(int(time.time() * 1000000))[-6:]
    if salt.utils.platform.is_windows():
        # ':' is an illegal filesystem path character on Windows
        stamp = time.strftime('%a_%b_%d_%H-%M-%S_%Y')
    else:
        stamp = time.strftime('%a_%b_%d_%H:%M:%S_%Y')
    stamp = '{0}{1}_{2}'.format(stamp[:-4], msecs, stamp[-4:])
    bkpath = os.path.join(bkroot,
                          src_dir,
                          '{0}_{1}'.format(bname, stamp))
    if not os.path.isdir(os.path.dirname(bkpath)):
        os.makedirs(os.path.dirname(bkpath))
    shutil.copyfile(path, bkpath)
    if not salt.utils.platform.is_windows():
        os.chown(bkpath, fstat.st_uid, fstat.st_gid)
        os.chmod(bkpath, fstat.st_mode)
454741
def _backup_pb_tqdm(self, dirs):
        """"""
        with ZipFile(self.zip_filename, 'w') as backup_zip:
            for path in tqdm(dirs, desc='Writing Zip Files', total=len(dirs)):
                backup_zip.write(path, path[len(self.source):len(path)])
448681
def linkorcopy(self, src, dst):
        """"""
        if os.path.isdir(dst):
            log.warn('linkorcopy given a directory as destination. '
                     'Use caution.')
            log.debug('src: %s  dst: %s', src, dst)
        elif os.path.exists(dst):
            os.unlink(dst)
        elif not os.path.exists(os.path.dirname(dst)):
            os.makedirs(os.path.dirname(dst))
        if self.linkfiles:
            log.debug('Linking: %s -> %s', src, dst)
            os.link(src, dst)
        else:
            log.debug('Copying: %s -> %s', src, dst)
            shutil.copy2(src, dst)
492081
def create_backup(self, instance, name, description=None):
        
        body = {"backup": {
                "instance": utils.get_id(instance),
                "name": name,
                }}
        if description is not None:
            body["backup"]["description"] = description
        uri = "/backups"
        resp, resp_body = self.api.method_post(uri, body=body)
        mgr = self.api._backup_manager
        return CloudDatabaseBackup(mgr, body.get("backup"))