aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Backups/BackupSettings.h
blob: 236084ff8110d19087e779cdaf94bf89f60621a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once

#include <Backups/BackupInfo.h>
#include <optional>


namespace DB
{
class ASTBackupQuery;

/// Settings specified in the "SETTINGS" clause of a BACKUP query.
struct BackupSettings
{
    /// ID of the backup operation, to identify it in the system.backups table. Auto-generated if not set.
    String id;

    /// Base backup, if it's set an incremental backup will be built. That means only differences made after the base backup will be put
    /// into a new backup.
    std::optional<BackupInfo> base_backup_info;

    /// Compression method and level for writing the backup (when applicable).
    String compression_method; /// "" means default method
    int compression_level = -1; /// -1 means default level

    /// Password used to encrypt the backup.
    String password;

    /// S3 storage class.
    String s3_storage_class = "";

    /// If this is set to true then only create queries will be written to backup,
    /// without the data of tables.
    bool structure_only = false;

    /// Whether the BACKUP command must return immediately without waiting until the backup has completed.
    bool async = false;

    /// Whether the BACKUP command should decrypt files stored on encrypted disks.
    bool decrypt_files_from_encrypted_disks = false;

    /// Whether the BACKUP will omit similar files (within one backup only).
    bool deduplicate_files = true;

    /// Whether native copy is allowed (optimization for cloud storages, that sometimes could have bugs)
    bool allow_s3_native_copy = true;

    /// Whether base backup to S3 should inherit credentials from the BACKUP query.
    bool use_same_s3_credentials_for_base_backup = false;

    /// Allow to use the filesystem cache in passive mode - benefit from the existing cache entries,
    /// but don't put more entries into the cache.
    bool read_from_filesystem_cache = true;

    /// 1-based shard index to store in the backup. 0 means all shards.
    /// Can only be used with BACKUP ON CLUSTER.
    size_t shard_num = 0;

    /// 1-based replica index to store in the backup. 0 means all replicas (see also allow_storing_multiple_replicas).
    /// Can only be used with BACKUP ON CLUSTER.
    size_t replica_num = 0;

    /// Internal, should not be specified by user.
    /// Whether this backup is a part of a distributed backup created by BACKUP ON CLUSTER.
    bool internal = false;

    /// Internal, should not be specified by user.
    /// The current host's ID in the format 'escaped_host_name:port'.
    String host_id;

    /// Internal, should not be specified by user.
    /// Cluster's hosts' IDs in the format 'escaped_host_name:port' for all shards and replicas in a cluster specified in BACKUP ON CLUSTER.
    std::vector<Strings> cluster_host_ids;

    /// Internal, should not be specified by user.
    /// UUID of the backup. If it's not set it will be generated randomly.
    std::optional<UUID> backup_uuid;

    static BackupSettings fromBackupQuery(const ASTBackupQuery & query);
    void copySettingsToQuery(ASTBackupQuery & query) const;

    struct Util
    {
        static std::vector<Strings> clusterHostIDsFromAST(const IAST & ast);
        static ASTPtr clusterHostIDsToAST(const std::vector<Strings> & cluster_host_ids);
        static std::pair<size_t, size_t> findShardNumAndReplicaNum(const std::vector<Strings> & cluster_host_ids, const String & host_id);
        static Strings filterHostIDs(const std::vector<Strings> & cluster_host_ids, size_t only_shard_num, size_t only_replica_num);
    };
};

}