Skip to content
Merged

dev #86

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ services:
# - cargo-target:/app/target
- databases_sqlite-data:/sqlite-data/workspace/data
- ./scripts/sqlite/test-db:/sqlite-data-2/workspace/data
# - /bigdisk:/scratch
environment:
APP_ENV: development
LOG: debug
TZ: "Europe/Paris"
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiZWZhYTM0YTQtZDY1NC00OGQ3LTgwNDYtNjRkMWExYTA1M2FlIiwibWFzdGVyS2V5QjY0IjoiMUh0djdtWCtYVkJxL0IzUEV2WDlZZjlQeUdVZW5oRHlXemo5THRqNW90WT0ifQ=="
# TMPDIR: /scratch
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiNTljYzRjYTUtOTAyNy00ZThiLTk1NDktMjAzOTI3ZDVjNmUyIiwibWFzdGVyS2V5QjY0IjoiMUh0djdtWCtYVkJxL0IzUEV2WDlZZjlQeUdVZW5oRHlXemo5THRqNW90WT0ifQ=="
Comment thread
RambokDev marked this conversation as resolved.
Resolved
#CHUNK_SIZE_MB: "1"
#POOLING: 1
#DATABASES_CONFIG_FILE: "config.toml"
Expand Down
2 changes: 2 additions & 0 deletions src/services/api/models/agent/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct DatabaseStorage {
#[serde(deserialize_with = "deserialize_snake_case")]
pub config: Value,
pub provider: String,
#[serde(default, rename = "folderName")]
pub folder_name: Option<String>,
}

#[derive(Debug, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/providers/azure_blob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl StorageProvider for AzureBlobProvider {
};

let file_name = full_file_name(encrypt);
let remote_file_path = full_file_path(&file_name);
let remote_file_path = full_file_path(&file_name, storage.folder_name.as_deref());
info!(
"Starting block upload to azure blob {}/{}",
config.container_name, remote_file_path
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/providers/google_cloud_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl StorageProvider for GoogleCloudStorageProvider {

let file_name = full_file_name(encrypt);
info!("Uploading file {}", file_name);
let remote_file_path = full_file_path(&file_name);
let remote_file_path = full_file_path(&file_name, storage.folder_name.as_deref());

let client = match build_client(&config).await {
Ok(c) => c,
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/providers/google_drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl StorageProvider for GoogleDriveProvider {

info!("Uploading file {}", file_name);

let remote_file_path = full_file_path(&file_name);
let remote_file_path = full_file_path(&file_name, storage.folder_name.as_deref());

match upload_stream_to_google_drive(
&config,
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/providers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl StorageProvider for LocalProvider {
let encrypt = encrypt.unwrap_or(false);

let file_name = full_file_name(encrypt);
let remote_file_path = full_file_path(&file_name);
let remote_file_path = full_file_path(&file_name, storage.folder_name.as_deref());

let total_size = match fs::metadata(&file_path).await {
Ok(meta) => meta.len(),
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage/providers/s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl StorageProvider for S3Provider {
info!("Uploading file {}", file_name);

let bucket = &config.bucket_name;
let remote_file_path = full_file_path(&file_name);
let remote_file_path = full_file_path(&file_name, storage.folder_name.as_deref());
info!("S3 key {:}", remote_file_path);
info!(
"Starting multipart upload to s3://{}/{}",
Expand Down
12 changes: 8 additions & 4 deletions src/tests/utils/file_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ fn full_file_name_matches_expected_suffix() {
}

#[test]
fn full_file_path_prefixes_backups_directory_and_date() {
fn full_file_path_uses_default_or_configured_folder_name() {
let file_name = "backup.tar.gz".to_string();
let full_path = full_file_path(&file_name);

assert!(full_path.starts_with("backups/"));
assert!(full_path.ends_with("/backup.tar.gz"));
let default_path = full_file_path(&file_name, None);
assert!(default_path.starts_with("backups/"));
assert!(default_path.ends_with("/backup.tar.gz"));

let configured_path = full_file_path(&file_name, Some("/portabase/"));
assert!(configured_path.starts_with("portabase/"));
assert!(configured_path.ends_with("/backup.tar.gz"));
}

#[tokio::test]
Expand Down
10 changes: 8 additions & 2 deletions src/utils/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ pub fn full_file_name(encrypt: bool) -> String {
}
}

pub fn full_file_path(file_name: &String) -> String {
format!("backups/{}/{}", Utc::now().format("%Y-%m-%d"), file_name)
pub fn full_file_path(file_name: &String, folder_name: Option<&str>) -> String {
let folder_name = folder_name
.map(str::trim)
.map(|folder_name| folder_name.trim_matches(char::from(47)))
.filter(|folder_name| !folder_name.is_empty())
.unwrap_or("backups");

format!("{}/{}/{}", folder_name, Utc::now().format("%Y-%m-%d"), file_name)
Comment thread
RambokDev marked this conversation as resolved.
Resolved
}

const CHUNK_SIZE: usize = 16 * 1024 * 1024;
Expand Down
Loading