write a backup function that will copy and zip my sqlite db to a blob, then write a function that exports the blob to a cloudfare api endpoint using post and encodable in swift
main.swift
import Foundation
funcbackupSQLiteDB(dbPath: String) -> Data? {
do {
let dbData =tryData(contentsOf: URL(fileURLWithPath: dbPath))
returntry dbData.gzipped()
} catch {
print("Error backing up SQLite DB: \(error)")
returnnil }
}
funcexportBackupToCloudflare(blob: Data, cloudflareURL: URL) {
var request =URLRequest(url: cloudflareURL)
request.httpMethod ="POST" request.setValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
request.httpBody = blob
let task =URLSession.shared.dataTask(with: request) { (data, response, error) iniflet error = error {
print("Error exporting backup to Cloudflare: \(error)")
}
iflet response = response as?HTTPURLResponse {
print("Response from Cloudflare API: \(response.statusCode)")
}
}
task.resume()
}