Restore a Cozy
        backup_file: path to .tar.gz
352099
def restore(backup_file):
    '''
        
    '''
    if not os.path.isfile(backup_file) and not os.path.islink(backup_file):
        print 'Missing backup file: {}'.format(backup_file)
    else:
        couchdb_path = _get_couchdb_path()

        print 'Restore Cozy:'
        cmd = 'supervisorctl stop cozy-controller ; sleep 10'
        cmd += ' ; service couchdb stop ; service nginx stop'
        cmd += ' ; rm -rf {couchdb_path}/.cozy_design'
        cmd += ' {couchdb_path}/_replicator.couch'
        cmd += ' ; tar xvzf {backup_file} -C /'
        cmd += ' ; service couchdb start ; service nginx start'
        cmd = cmd.format(backup_file=backup_file, couchdb_path=couchdb_path)
        helpers.cmd_exec(cmd, show_output=True)
        helpers.wait_couchdb(10)
        cmd = 'supervisorctl start cozy-controller'
        helpers.cmd_exec(cmd, show_output=True)
1356326
def repackage(path)
      @logger.debug("Repackaging box '#{@name}' to: #{path}")

      Util::SafeChdir.safe_chdir(@directory) do
        # Find all the files in our current directory and tar it up!
        files = Dir.glob(File.join(".", "**", "*")).select { |f| File.file?(f) }

        # Package!
        Util::Subprocess.execute("bsdtar", "-czf", path.to_s, *files)
      end

      @logger.info("Repackaged box '#{@name}' successfully: #{path}")

      true
    end
1175642
def restore(source, offset):
    
    backup_location = os.path.join(
        os.path.dirname(os.path.abspath(source)), source + '.bytes_backup')
    click.echo('Reading backup from: {location}'.format(location=backup_location))

    if not os.path.isfile(backup_location):
        click.echo('No backup found for: {source}'.format(source=source))
        return

    with open(backup_location, 'r+b') as b:
        data = b.read()

    click.echo('Restoring {c} bytes from offset {o}'.format(c=len(data), o=offset))
    with open(source, 'r+b') as f:
        f.seek(offset)
        f.write(data)
        f.flush()

    click.echo('Changes written')
1172688
def cache_path(archive, root_dir, build_id):
    
    root = root_dir or Path("~/.shiv").expanduser()
    name = Path(archive.filename).resolve().stem
    return root / f"{name}_{build_id}"
238297
def decompress(self, image_path, quiet=True):
    ''''''

    if not os.path.exists(image_path):
        bot.exit("Cannot find image %s" %image_path)
        
    extracted_file = image_path.replace('.gz','')
    cmd = ['gzip','-d','-f', image_path]
    result = self.run_command(cmd, quiet=quiet) # exits if return code != 0
    return extracted_file
1347254
def unpack_tarball(tgz)
      Dir.chdir(config.ruby_toplevel_dir) do
        each_compressed_file(tgz) do |path, entry|
          debug "Unpacking file: #{path}"
          File.open(path, 'wb') do |f|
            f.write(entry.read)
          end
        end
      end
    end
1201673
def zipper(root_dir="", name="", path_name_ext=""):
    
    logger_zips.info("re_zip: name: {}, dir_tmp: {}".format(path_name_ext, root_dir))
    # creates a zip archive in current directory. "somefile.lpd.zip"
    shutil.make_archive(path_name_ext, format='zip', root_dir=root_dir, base_dir=name)
    # drop the .zip extension. only keep .lpd
    os.rename("{}.zip".format(path_name_ext), path_name_ext)
    return
757994
def build_package
      filename = config.tarball_filename(config.toml[:package][:version])
      relative_library_path = config.ruby_extension_path.sub("#{config.ruby_toplevel_dir}/", '')
      prepare_built_library
      Zlib::GzipWriter.open(filename) do |tgz|
        Dir.chdir(config.ruby_toplevel_dir) do
          Archive::Tar::Minitar.pack(relative_library_path, tgz)
        end
      end
    end
257594
def current_zipfile():
    """"""
    if zipfile.is_zipfile(sys.argv[0]):
        fd = open(sys.argv[0], "rb")
        return zipfile.ZipFile(fd)
220118
def _get_save_path(self, bury=False):
        """"""
        filename = self.get_filename(self[self._KEYS.NAME])

        # Put objects that shouldn't belong in this catalog in the boneyard
        if bury:
            outdir = self.catalog.get_repo_boneyard()

        # Get normal repository save directory
        else:
            repo_folders = self.catalog.PATHS.get_repo_output_folders()
            # If no repo folders exist, raise an error -- cannot save
            if not len(repo_folders):
                err_str = (
                    "No output data repositories found. Cannot save.\n"
                    "Make sure that repo names are correctly configured "
                    "in the `input/repos.json` file, and either manually or "
                    "automatically (using `astrocats CATALOG git-clone`) "
                    "clone the appropriate data repositories.")
                self.catalog.log.error(err_str)
                raise RuntimeError(err_str)

            outdir = repo_folders[0]

        return outdir, filename
1133684
def find_files_for_tar(self, context, silent_build):
        
        if not context.enabled:
            return

        files = self.find_files(context, silent_build)

        for path in files:
            relname = os.path.relpath(path, context.parent_dir)
            arcname = "./{0}".format(relname.encode('utf-8').decode('ascii', 'ignore'))
            if os.path.exists(path):
                yield path, arcname
123741
def backup_restore(cls, block_id, impl, working_dir):
        
        backup_dir = config.get_backups_directory(impl, working_dir)
        backup_paths = cls.get_backup_paths(block_id, impl, working_dir)
        for p in backup_paths:
            assert os.path.exists(p), "No such backup file: {}".format(p)

        for p in cls.get_state_paths(impl, working_dir):
            pbase = os.path.basename(p)
            backup_path = os.path.join(backup_dir, pbase + (".bak.{}".format(block_id)))
            log.debug("Restoring '{}' to '{}'".format(backup_path, p))
            shutil.copy(backup_path, p)
    
        return True
315759
def remote(self, *args):
        
        log_path = args[0]
        ChangeLog_txt = args[1]
        lib_path = args[2]
        PACKAGES_TXT = args[3]
        CHECKSUMS_MD5 = args[4]
        FILELIST_TXT = args[5]
        repo = args[6]

        if self.checks_logs(log_path, ChangeLog_txt):
            # remove old files
            self.file_remove(log_path, ChangeLog_txt.split("/")[-1])
            self.file_remove(lib_path, PACKAGES_TXT.split("/")[-1])
            self.file_remove(lib_path, CHECKSUMS_MD5.split("/")[-1])
            self.file_remove(lib_path, FILELIST_TXT.split("/")[-1])
            if repo == "slack":
                dirs = ["core/", "extra/", "pasture/"]
                for d in dirs:
                    self.file_remove(lib_path + d, "PACKAGES.TXT")
                    self.file_remove(lib_path + d, "CHECKSUMS.md5")
                self.down(lib_path + "core/", PACKAGES_TXT, repo)
                self.down(lib_path + "core/", CHECKSUMS_MD5, repo)
                self.down(lib_path + "extra/", self.EXTRA, repo)
                self.down(lib_path + "extra/", self.EXT_CHECKSUMS, repo)
                if slack_ver() != "14.0":  # no pasture/ folder for 14.0 version
                    self.down(lib_path + "pasture/", self.PASTURE, repo)
                    self.down(lib_path + "pasture/", self.PAS_CHECKSUMS, repo)
            # download new files
            if repo != "slack":
                self.down(lib_path, PACKAGES_TXT, repo)
                self.down(lib_path, CHECKSUMS_MD5, repo)
            self.down(lib_path, FILELIST_TXT, repo)
            self.down(log_path, ChangeLog_txt, repo)
1242098
def _backup_file(path):
    
    backup_base = '/var/local/woven-backup'
    backup_path = ''.join([backup_base,path])
    if not exists(backup_path):
        directory = ''.join([backup_base,os.path.split(path)[0]])
        sudo('mkdir -p %s'% directory)
        sudo('cp %s %s'% (path,backup_path))
1128024
def makeBackupFile(self, dstPath, fileName):
        

        with open(os.devnull) as devnull:
            SP.call(['mongodump', '--db', self.dbName, '--out', dstPath],
                    stdout=devnull,
                    stderr=devnull)
            SP.call(['zip',
                     '-r',
                     os.path.join(dstPath, fileName),
                     os.path.join(dstPath, self.dbName)],
                    stdout=devnull,
                    stderr=devnull)

        SP.call(['rm', '-rf', os.path.join(dstPath, self.dbName)])
1180053
def Rsync(url, tgt_name, tgt_root=None):
    
    if tgt_root is None:
        tgt_root = str(CFG["tmp_dir"])

    from benchbuild.utils.cmd import rsync

    tgt_dir = local.path(tgt_root) / tgt_name
    if not source_required(tgt_dir):
        Copy(tgt_dir, ".")
        return

    rsync("-a", url, tgt_dir)
    update_hash(tgt_dir)
    Copy(tgt_dir, ".")
655805
def _dir_tar_out(self):
        """"""
        return os.path.join(self.proj.tar_direc_out, self.proj.name,
                            self.model.name, self.run.name)