Class: Appwrite::Backups

Inherits:
Service show all
Defined in:
lib/appwrite/services/backups.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Backups

Returns a new instance of Backups.



5
6
7
# File 'lib/appwrite/services/backups.rb', line 5

def initialize(client)
    @client = client
end

Instance Method Details

#create_archive(services:, resource_id: nil) ⇒ BackupArchive

Create a new archive asynchronously for a project.

Parameters:

  • services (Array) —

    Array of services to backup

  • resource_id (String) (defaults to: nil) —

    Resource ID. When set, only this single resource will be backed up.

Returns:

  • (BackupArchive)


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
# File 'lib/appwrite/services/backups.rb', line 46

def create_archive(
    services:,
    resource_id: nil
)
    if services.nil?
        raise Appwrite::Exception.new('Missing required parameter: "services"')
    end

    api_path = '/backups/archives'

    api_params = {
        services: services,
        resourceId: resource_id,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupArchive
    )
end

#create_policy(policy_id:, services:, retention:, schedule:, name: nil, resource_id: nil, enabled: nil) ⇒ BackupPolicy

Create a new backup policy.

Parameters:

  • policy_id (String) —

    Policy ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • services (Array) —

    Array of services to backup

  • retention (Integer) —

    Days to keep backups before deletion

  • schedule (String) —

    Schedule CRON syntax.

  • name (String) (defaults to: nil) —

    Policy name. Max length: 128 chars.

  • resource_id (String) (defaults to: nil) —

    Resource ID. When set, only this single resource will be backed up.

  • [] —

    enabled Is policy enabled? When set to 'disabled', no backups will be taken

Returns:

  • (BackupPolicy)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/appwrite/services/backups.rb', line 180

def create_policy(
    policy_id:,
    services:,
    retention:,
    schedule:,
    name: nil,
    resource_id: nil,
    enabled: nil
)
    if policy_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "policyId"')
    end

    if services.nil?
        raise Appwrite::Exception.new('Missing required parameter: "services"')
    end

    if retention.nil?
        raise Appwrite::Exception.new('Missing required parameter: "retention"')
    end

    if schedule.nil?
        raise Appwrite::Exception.new('Missing required parameter: "schedule"')
    end

    api_path = '/backups/policies'

    api_params = {
        policyId: policy_id,
        name: name,
        services: services,
        resourceId: resource_id,
        enabled: enabled,
        retention: retention,
        schedule: schedule,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupPolicy
    )
end

#create_restoration(archive_id:, services:, new_resource_id: nil, new_resource_name: nil) ⇒ BackupRestoration

Create and trigger a new restoration for a backup on a project.

For a backup of one database, the restoration resolves its destination before it is queued. When newResourceId is omitted, the archived database is restored in place and its own ID is returned in options. Pass a different newResourceId to restore alongside it as a new database instead.

The restoration migration records the archived database in resourceId and resourceType, and the resolved database in destinationResourceId and destinationResourceType. Database types are stored canonically as database, documentsdb, or vectorsdb. Project-wide restorations leave these fields empty because they do not have a single source or destination database.

To list every migration related to one database, use its canonical type in a nested OR(AND(...), AND(...), AND(...)) across the root, parent, and destination relation pairs: (resourceType, resourceId), (parentResourceType, parentResourceId), and (destinationResourceType, destinationResourceId). Legacy and TablesDB databases use database; the operational resourceType of a table migration is not rewritten to tablesdb.

When restoring a DocumentsDB or VectorsDB database from a dedicated source, the restore provisions a fresh dedicated backing database at the source database's own specification and lands the data there. An in-place restore swaps the database onto that backing only once the restore has succeeded, and retires the backing it displaced only once that swap is confirmed, so the source keeps serving its own data until the restored data is in place and any failure leaves it untouched. A serverless source has no dedicated backing to clone and restores onto the archived database instead.

Parameters:

  • archive_id (String) —

    Backup archive ID to restore

  • services (Array) —

    Array of services to restore

  • new_resource_id (String) (defaults to: nil) —

    Destination resource ID. Omit to restore the archived resource in place, or pass a different ID to restore alongside it as a new resource. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • new_resource_name (String) (defaults to: nil) —

    Database name. Max length: 128 chars.

Returns:

  • (BackupRestoration)


378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/appwrite/services/backups.rb', line 378

def create_restoration(
    archive_id:,
    services:,
    new_resource_id: nil,
    new_resource_name: nil
)
    if archive_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "archiveId"')
    end

    if services.nil?
        raise Appwrite::Exception.new('Missing required parameter: "services"')
    end

    api_path = '/backups/restoration'

    api_params = {
        archiveId: archive_id,
        services: services,
        newResourceId: new_resource_id,
        newResourceName: new_resource_name,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupRestoration
    )
end

#delete_archive(archive_id:) ⇒ Object

Delete an existing archive for a project.

Parameters:

  • archive_id (String) —

    Policy ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

Returns:

  • []



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/appwrite/services/backups.rb', line 112

def delete_archive(
    archive_id:
)
    if archive_id.nil? || archive_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "archiveId"')
    end

    api_path = '/backups/archives/{archiveId}'
        .gsub('{archiveId}', @client.encode_path(archive_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#delete_policy(policy_id:) ⇒ Object

Delete a policy using it's ID.

Parameters:

  • policy_id (String) —

    Policy ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

Returns:

  • []



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/appwrite/services/backups.rb', line 313

def delete_policy(
    policy_id:
)
    if policy_id.nil? || policy_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "policyId"')
    end

    api_path = '/backups/policies/{policyId}'
        .gsub('{policyId}', @client.encode_path(policy_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#get_archive(archive_id:) ⇒ BackupArchive

Get a backup archive using it's ID.

Parameters:

  • archive_id (String) —

    Archive ID. Choose a custom ID`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

Returns:

  • (BackupArchive)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/appwrite/services/backups.rb', line 81

def get_archive(
    archive_id:
)
    if archive_id.nil? || archive_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "archiveId"')
    end

    api_path = '/backups/archives/{archiveId}'
        .gsub('{archiveId}', @client.encode_path(archive_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupArchive
    )
end

#get_policy(policy_id:) ⇒ BackupPolicy

Get a backup policy using it's ID.

Parameters:

  • policy_id (String) —

    Policy ID. Choose a custom ID`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

Returns:

  • (BackupPolicy)


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/appwrite/services/backups.rb', line 237

def get_policy(
    policy_id:
)
    if policy_id.nil? || policy_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "policyId"')
    end

    api_path = '/backups/policies/{policyId}'
        .gsub('{policyId}', @client.encode_path(policy_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupPolicy
    )
end

#get_restoration(restoration_id:) ⇒ BackupRestoration

Get the current status of a backup restoration.

Parameters:

  • restoration_id (String) —

    Restoration ID. Choose a custom ID`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

Returns:

  • (BackupRestoration)


452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/appwrite/services/backups.rb', line 452

def get_restoration(
    restoration_id:
)
    if restoration_id.nil? || restoration_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "restorationId"')
    end

    api_path = '/backups/restorations/{restorationId}'
        .gsub('{restorationId}', @client.encode_path(restoration_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupRestoration
    )
end

#list_archives(queries: nil, total: nil) ⇒ BackupArchiveList

List all archives for a project.

Parameters:

  • queries (Array) (defaults to: nil) —

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (BackupArchiveList)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/appwrite/services/backups.rb', line 15

def list_archives(
    queries: nil,
    total: nil
)
    api_path = '/backups/archives'

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupArchiveList
    )
end

#list_policies(queries: nil, total: nil) ⇒ BackupPolicyList

List all policies for a project.

Parameters:

  • queries (Array) (defaults to: nil) —

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (BackupPolicyList)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/appwrite/services/backups.rb', line 144

def list_policies(
    queries: nil,
    total: nil
)
    api_path = '/backups/policies'

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupPolicyList
    )
end

#list_restorations(queries: nil, total: nil) ⇒ BackupRestorationList

List all backup restorations for a project.

Parameters:

  • queries (Array) (defaults to: nil) —

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (BackupRestorationList)


422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/appwrite/services/backups.rb', line 422

def list_restorations(
    queries: nil,
    total: nil
)
    api_path = '/backups/restorations'

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupRestorationList
    )
end

#update_policy(policy_id:, name: nil, retention: nil, schedule: nil, enabled: nil) ⇒ BackupPolicy

Update an existing policy using it's ID.

Parameters:

  • policy_id (String) —

    Policy ID. Choose a custom ID`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • name (String) (defaults to: nil) —

    Policy name. Max length: 128 chars.

  • retention (Integer) (defaults to: nil) —

    Days to keep backups before deletion

  • schedule (String) (defaults to: nil) —

    Cron expression

  • [] —

    enabled Is Backup enabled? When set to 'disabled', No backup will be taken

Returns:

  • (BackupPolicy)


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/appwrite/services/backups.rb', line 272

def update_policy(
    policy_id:,
    name: nil,
    retention: nil,
    schedule: nil,
    enabled: nil
)
    if policy_id.nil? || policy_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "policyId"')
    end

    api_path = '/backups/policies/{policyId}'
        .gsub('{policyId}', @client.encode_path(policy_id))

    api_params = {
        name: name,
        retention: retention,
        schedule: schedule,
        enabled: enabled,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::BackupPolicy
    )
end