MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerDatabaseBackup

Function registerDatabaseBackup

src/Databases/DatabaseBackup.cpp:470–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468
469void registerDatabaseBackup(DatabaseFactory & factory);
470void registerDatabaseBackup(DatabaseFactory & factory)
471{
472 auto create_fn = [](const DatabaseFactory::Arguments & args)
473 {
474 auto * engine_define = args.create_query.storage;
475 const ASTFunction * engine = engine_define->engine;
476
477 ASTs engine_args;
478 if (engine->arguments)
479 engine_args = engine->arguments->children;
480
481 auto config = parseArguments(engine_args, args.context);
482 return std::make_shared<DatabaseBackup>(args.database_name, args.metadata_path, config, args.context);
483 };
484
485 factory.registerDatabase("Backup", create_fn, {.supports_arguments = true, .is_external = true}, Documentation{
486 .description = R"DOCS_MD(
487Database backup allows to instantly attach table/database from [backups](/operations/backup/overview) in read-only mode.
488
489Database backup works with both incremental and non-incremental backups.
490
491## Creating a database {#creating-a-database}
492
493```sql
494CREATE DATABASE backup_database
495ENGINE = Backup('database_name_inside_backup', Disk('disk_name', 'backup_name'))
496```
497
498The backup destination can be any valid backup [destination](/operations/backup/disk#configure-backup-destinations-for-disk), such as `Disk`, `S3`, or `File`. It is passed as a function, for example `Disk('disk_name', 'backup_name')`.
499
500**Engine Parameters**
501
502- `database_name_inside_backup` — Name of the database inside the backup.
503- `backup_destination` — Backup destination.
504
505## Usage example {#usage-example}
506
507Let's make an example with a `Disk` backup destination. Let's first setup backups disk in `storage.xml`:
508
509```xml
510<storage_configuration>
511 <disks>
512 <backups>
513 <type>local</type>
514 <path>/home/ubuntu/ClickHouseWorkDir/backups/</path>
515 </backups>
516 </disks>
517</storage_configuration>
518<backups>
519 <allowed_disk>backups</allowed_disk>
520 <allowed_path>/home/ubuntu/ClickHouseWorkDir/backups/</allowed_path>
521</backups>
522```
523
524Example of usage. Let's create test database, tables, insert some data and then create a backup:
525
526```sql
527CREATE DATABASE test_database;

Callers 1

registerDatabasesFunction · 0.85

Calls 2

registerDatabaseMethod · 0.80
parseArgumentsFunction · 0.70

Tested by

no test coverage detected