예제 #1
0
 def __init__(
     self,
     url: Union[str, URL],
     app: AppT,
     table: CollectionT,
     *,
     key_index_size: Optional[int] = None,
     options: Optional[Mapping[str, Any]] = None,
     read_only: Optional[bool] = False,
     **kwargs: Any,
 ) -> None:
     if rocksdb is None:
         error = ImproperlyConfigured(
             "RocksDB bindings not installed? pip install python-rocksdb"
         )
         try:
             import rocksdb as _rocksdb  # noqa: F401
         except Exception as exc:  # pragma: no cover
             raise error from exc
         else:  # pragma: no cover
             raise error
     super().__init__(url, app, table, **kwargs)
     if not self.url.path:
         self.url /= self.table_name
     self.options = options or {}
     self.read_only = self.options.pop("read_only", read_only)
     self.rocksdb_options = RocksDBOptions(**self.options)
     if key_index_size is None:
         key_index_size = app.conf.table_key_index_size
     self.key_index_size = key_index_size
     self._dbs = {}
     self._key_index = LRUCache(limit=self.key_index_size)
     self.db_lock = asyncio.Lock()
     self.rebalance_ack = False
     self._backup_path = os.path.join(self.path, f"{str(self.basename)}-backups")
     try:
         self._backup_engine = None
         if not os.path.isdir(self._backup_path):
             os.makedirs(self._backup_path, exist_ok=True)
         testfile = tempfile.TemporaryFile(dir=self._backup_path)
         testfile.close()
     except PermissionError:
         self.log.warning(
             f'Unable to make directory for path "{self._backup_path}",'
             f"disabling backups."
         )
     except OSError:
         self.log.warning(
             f'Unable to create files in "{self._backup_path}",' f"disabling backups"
         )
     else:
         self._backup_engine = rocksdb.BackupEngine(self._backup_path)
예제 #2
0
def main(argv):
    inputfile = ''
    try:
      opts, args = getopt.getopt(argv,"hd:o:",["database="])
    except getopt.GetoptError:
      print 'rocksdb_backup.py -d database_name [e]'
      sys.exit(2)
    for opt, arg in opts:
      if opt == '-h':
         print 'rocksdb_backup.py -d database_name '
         sys.exit()
      elif opt in ("-d", "--database"):
         inputfile = arg
         print 'Database to be backed up', inputfile
         db = rocksdb.DB(inputfile, rocksdb.Options(create_if_missing=False))
         backup = rocksdb.BackupEngine("./backups.bk")
         backup.create_backup(db, flush_before_backup=True)
         print 'Database ', inputfile, ' has been successfully backed up ', os.getcwd(), '/backups.bk'
      else:
         assert False, "Invalid Options"
예제 #3
0
import rocksdb

db = rocksdb.DB('/db/db', rocksdb.Options())
backup = rocksdb.BackupEngine("/pyrocksdb_backups")

backup.create_backup(db, flush_before_backup=True)
예제 #4
0
 def restore_latest_backup(self, path):
     backup = rocksdb.BackupEngine(path)
     self.close()
     r = backup.restore_latest_backup(self.data_dir, self.data_dir)
     self.rdb = self.open()
     return r
예제 #5
0
 def purge_old_backups(self, path, num_backups_to_keep):
     backup = rocksdb.BackupEngine(path)
     self.close()
     r = backup.purge_old_backups(num_backups_to_keep)
     self.rdb = self.open()
     return r
예제 #6
0
 def restore_backup(self, path, backup_id):
     backup = rocksdb.BackupEngine(path)
     return backup.restore_backup(backup_id, self.data_dir, self.data_dir)
예제 #7
0
 def get_backup_info(self, path):
     backup = rocksdb.BackupEngine(path)
     return backup.get_backup_info()
예제 #8
0
 def delete_backup(self, path, backup_id):
     backup = rocksdb.BackupEngine(path)
     return backup.delete_backup(backup_id)
예제 #9
0
 def stop_backup(self, path):
     backup = rocksdb.BackupEngine(path)
     return backup.stop_backup()
예제 #10
0
 def create_backup(self, path):
     backup = rocksdb.BackupEngine(path)
     return backup.create_backup(self.rdb, flush_before_backup=True)