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.



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

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)


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

def create_archive(services:, resource_id: nil)
    api_path = '/backups/archives'

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

    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)


171
172
173
174
175
176
177
178
179
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
# File 'lib/appwrite/services/backups.rb', line 171

def create_policy(policy_id:, services:, retention:, schedule:, name: nil, resource_id: nil, enabled: nil)
    api_path = '/backups/policies'

    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_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, new_specification: nil) ⇒ BackupRestoration

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

When restoring a DocumentsDB or VectorsDB database to a new resource, pass newSpecification to provision the restored database on a different specification than the archived one (for example, restoring onto a larger or smaller dedicated database). Use serverless to restore onto the shared pool, or a dedicated specification slug to restore onto a dedicated database of that size. The specification must be permitted by the organization's plan. newSpecification is not supported for legacy/TablesDB databases or for bucket restores.

Parameters:

  • archive_id (String)

    Backup archive ID to restore

  • services (Array)

    Array of services to restore

  • new_resource_id (String) (defaults to: nil)

    Unique 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.

  • new_resource_name (String) (defaults to: nil)

    Database name. Max length: 128 chars.

  • new_specification (String) (defaults to: nil)

    Specification to provision the restored database on, when restoring a DocumentsDB or VectorsDB database to a new resource. Defaults to the archived database's specification. Use serverless for the shared pool or a dedicated specification slug.

Returns:

  • (BackupRestoration)


337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/appwrite/services/backups.rb', line 337

def create_restoration(archive_id:, services:, new_resource_id: nil, new_resource_name: nil, new_specification: nil)
    api_path = '/backups/restoration'

    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_params = {
        archiveId: archive_id,
        services: services,
        newResourceId: new_resource_id,
        newResourceName: new_resource_name,
        newSpecification: new_specification,
    }
    
    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:

  • []



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/appwrite/services/backups.rb', line 107

def delete_archive(archive_id:)
    api_path = '/backups/archives/{archiveId}'
        .gsub('{archiveId}', archive_id)

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

    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:

  • []



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/appwrite/services/backups.rb', line 292

def delete_policy(policy_id:)
    api_path = '/backups/policies/{policyId}'
        .gsub('{policyId}', policy_id)

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

    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)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/appwrite/services/backups.rb', line 76

def get_archive(archive_id:)
    api_path = '/backups/archives/{archiveId}'
        .gsub('{archiveId}', archive_id)

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

    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)


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/appwrite/services/backups.rb', line 221

def get_policy(policy_id:)
    api_path = '/backups/policies/{policyId}'
        .gsub('{policyId}', policy_id)

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

    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)


404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/appwrite/services/backups.rb', line 404

def get_restoration(restoration_id:)
    api_path = '/backups/restorations/{restorationId}'
        .gsub('{restorationId}', restoration_id)

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

    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) ⇒ 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.

Returns:

  • (BackupArchiveList)


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

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

    api_params = {
        queries: queries,
    }
    
    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) ⇒ 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.

Returns:

  • (BackupPolicyList)


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/appwrite/services/backups.rb', line 138

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

    api_params = {
        queries: queries,
    }
    
    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) ⇒ 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.

Returns:

  • (BackupRestorationList)


377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/appwrite/services/backups.rb', line 377

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

    api_params = {
        queries: queries,
    }
    
    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)


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/appwrite/services/backups.rb', line 256

def update_policy(policy_id:, name: nil, retention: nil, schedule: nil, enabled: nil)
    api_path = '/backups/policies/{policyId}'
        .gsub('{policyId}', policy_id)

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

    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