Restore bucket from SQL
771093
def restore_bucket(self, table_name):
        
        if table_name.startswith(self.__prefix):
            return table_name.replace(self.__prefix, '', 1)
        return None
388039
def restore(ctx, filename):
    
    filename = filename or background_path
    if not os.path.isfile(filename):
        LOG.warning("File {} does not exist. Please point to a valid file".format(filename))
        ctx.abort()
    
    call = ['mongorestore', '--gzip', '--db', 'loqusdb', '--archive={}'.format(filename)]
    
    LOG.info('Restoring database from %s', filename)
    start_time = datetime.now()
    try:
        completed = subprocess.run(call, check=True)
    except subprocess.CalledProcessError as err:
        LOG.warning(err)
        ctx.abort()
    
    LOG.info('Database restored succesfully')
    LOG.info('Time to restore database: {0}'.format(datetime.now()-start_time))
1037732
def get_commands_from_dir(directory, zip_backup=True, remove_dir=True):
    """"""
    # Get SQL commands file paths
    failed_scripts = sorted([os.path.join(directory, fn) for fn in os.listdir(directory) if fn.endswith('.sql')])

    # Read each failed SQL file and append contents to a list
    print('\tReading SQL scripts from files')
    commands = []
    for sql_file in failed_scripts:
        with open(sql_file, 'r') as txt:
            sql_command = txt.read()
        commands.append(sql_command)

    # Remove most recent failures folder after reading
    if zip_backup:
        ZipBackup(directory).backup()
    if remove_dir:
        shutil.rmtree(directory)
    return commands
1162856
def save_sql_to_files(overwrite=False):
    
    ext_size = len(SQL_EXTENSION)
    path = DATA_PATH / 'scripts'
    save_dir = DATA_PATH / "raw"

    for file in os.listdir(path):
        if file.endswith(SQL_EXTENSION):
            file_path = os.path.join(save_dir,
                                     file[:-ext_size] + '.' + FILE_EXTENSION)
            if not os.path.isfile(file_path) or overwrite:
                query_result = make_query(path / file)
                save_dataframe_as_pickle(query_result, file_path)
            else:
                print(("file {} already exists, if you would like to update"
                       " it, use -f flag\n").format(file_path))
1240873
public function restore()
    {
        //translate model data to sql data
        if (is_null($this->schema)) {
            throw Exception::forNoSchema();
        }

        $data = $this->schema->toSql();

        //queries to run
        $queries = [];

        // check if table is already archived
        if ($this->exists($data['name'])) {
            throw Exception::forSchemaAlreadyExists($data['name']);
        }

        //if there's no system
        if (!$this->exists('_' . $data['name'])) {
            //go to create mode
            return $this->create($data, true);
        }

        $queries[] = 'RENAME TABLE `_' . $data['name'] . '` TO `' . $data['name'] . '`;';

        //determine the relation schema
        foreach ($data['relations'] as $table => $relation) {
            $queries[] = 'RENAME TABLE `_' . $table . '` TO `' . $table . '`;';
        }

        //execute queries
        $results = [];
        foreach ($queries as $query) {
            $results[] = [
                'query' => $query,
                'results' => $this->resource->query($query)
            ];
        }

        return $results;
    }
907661
def restore(self):
        
        # If there are no backup keys, do nothing...
        if len(list(self.backup.keys())) == 0:
            return
        for key in self.backup.keys():
            if key != 'WCSCDATE':
                self.__dict__[self.wcstrans[key]] = self.orig_wcs[self.backup[key]]

        self.update()
809798
def from_bucket(self, bucket, native=False):
    '''
    
    '''
    # NOTE: this is due to a bug somewhere in strptime that does not process
    # the week number of '%Y%U' correctly. That bug could be very specific to
    # the combination of python and ubuntu that I was testing.
    bucket = str(bucket)
    if self._step == 'weekly':
      year, week = bucket[:4], bucket[4:]
      normal = datetime(year=int(year), month=1, day=1) + timedelta(weeks=int(week))
    else:
      normal = datetime.strptime(bucket, self.FORMATS[self._step])
    if native:
      return normal
    return long(time.mktime( normal.timetuple() ))
1135682
def restore_collection(backup):
    
    for k, v in six.iteritems(backup):
        del tf.get_collection_ref(k)[:]
        tf.get_collection_ref(k).extend(v)
518916
def create_bucket(self, bucket):
        
        details = self._details(
            method=b"PUT",
            url_context=self._url_context(bucket=bucket),
        )
        query = self._query_factory(details)
        return self._submit(query)
356771
def get_bucket(self, environment, name, filename, source):
        
        key = self.get_cache_key(name, filename)
        checksum = self.get_source_checksum(source)
        bucket = Bucket(environment, key, checksum)
        self.load_bytecode(bucket)
        return bucket
146493
def dumps(self):
        """"""
        self.data.update({
            'bucket': str(self.obj.bucket_id),
            'checksum': self.obj.file.checksum,
            'key': self.obj.key,  # IMPORTANT it must stay here!
            'size': self.obj.file.size,
            'version_id': str(self.obj.version_id),
        })
        return self.data
201184
def _get_db():
    
    with cd(env.remote_path):
        file_path = '/tmp/' + _sql_paths('remote', str(base64.urlsafe_b64encode(uuid.uuid4().bytes)).replace('=', ''))
        run(env.python + ' manage.py dump_database | gzip > ' + file_path)
        local_file_path = './backups/' + _sql_paths('remote', datetime.now())
    get(file_path, local_file_path)
    run('rm ' + file_path)
    return local_file_path
581669
def buckets(self):
        
        buckets = []
        for table in self.__metadata.sorted_tables:
            bucket = self.__mapper.restore_bucket(table.name)
            if bucket is not None:
                buckets.append(bucket)
        return buckets
14112
def inspect_bucket(bucket):
    """"""
    state = db.db()
    found = None
    for b in state.buckets():
        if b.name == bucket:
            found = b
    if not found:
        click.echo("no bucket named: %s" % bucket)
        return

    click.echo("Bucket: %s" % found.name)
    click.echo("Account: %s" % found.account)
    click.echo("Region: %s" % found.region)
    click.echo("Created: %s" % found.created)
    click.echo("Size: %s" % found.size)
    click.echo("Inventory: %s" % found.inventory)
    click.echo("Partitions: %s" % found.partitions)
    click.echo("Scanned: %0.2f%%" % found.percent_scanned)
    click.echo("")
    click.echo("Errors")

    click.echo("Denied: %s" % found.keys_denied)
    click.echo("BErrors: %s" % found.error_count)
    click.echo("KErrors: %s" % found.data['keys-error'].get(found.bucket_id, 0))
    click.echo("Throttle: %s" % found.data['keys-throttled'].get(found.bucket_id, 0))
    click.echo("Missing: %s" % found.data['keys-missing'].get(found.bucket_id, 0))
    click.echo("Session: %s" % found.data['keys-sesserr'].get(found.bucket_id, 0))
    click.echo("Connection: %s" % found.data['keys-connerr'].get(found.bucket_id, 0))
    click.echo("Endpoint: %s" % found.data['keys-enderr'].get(found.bucket_id, 0))
710705
def bucket(things, key):
    """"""
    ret = defaultdict(list)
    for thing in things:
        ret[key(thing)].append(thing)
    return ret
590397
function restore (s) {
    s.blksize = 4096;
    s.blocks = 0;
    s.dev = 0;
    s.gid = 20;
    s.ino = 0;
    s.nlink = 0;
    s.rdev = 0;
    s.uid = 500;

    s.atime = new Date(EXECSTAT.atime);
    s.mtime = new Date(EXECSTAT.mtime);
    s.ctime = new Date(EXECSTAT.ctime);
    s.birthtime = new Date(EXECSTAT.birthtime);

    s.atimeMs = EXECSTAT.atimeMs;
    s.mtimeMs = EXECSTAT.mtimeMs;
    s.ctimeMs = EXECSTAT.ctimeMs;
    s.birthtimeMs = EXECSTAT.birthtimeMs;

    var isFileValue = s.isFileValue;
    var isDirectoryValue = s.isDirectoryValue;
    delete s.isFileValue;
    delete s.isDirectoryValue;

    s.isFile = function () {
      return isFileValue;
    };
    s.isDirectory = function () {
      return isDirectoryValue;
    };
    s.isSymbolicLink = function () {
      return false;
    };
    s.isFIFO = function () {
      return false;
    };

    return s;
  }
708178
def restore(self, request):
        
        self._connection.connection.rpush(self._request_key, pickle.dumps(request))