diff --git a/Cargo.toml b/Cargo.toml index f65ec6a..bc4ec94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,12 @@ [package] name = "xdbm" version = "0.1.0" +authors = ["qwjyh "] edition = "2021" +description = "Cross device backup manager, to manage backups on several storages mounted on multiple devices." +homepage = "https://github.com/qwjyh/xdbm" +repository = "https://github.com/qwjyh/xdbm" +license = "MIT OR Apache-1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index a8dcb7a..1809166 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,15 @@ -# TODO: +# xdbm +_Cross device backup manager_, +to manage backups on several storages mounted on multiple devices with a single repository. + +## Usage +1. `xdbm init` to setup new device(i.e. PC). +2. `xdbm storage add` to add storages, or `xdbm storage bind` to make existing storages available on new device. +3. `xdbm backup add` to add new backup configuration. +4. `xdbm backup done` to tell xdbm to write backup execution datetime. +5. `xdbm storage list` and `xdbm backup list` to see their status. + +## TODO: - [x] split subcommands to functions - [x] write test for init subcommand - [x] write test with existing repo diff --git a/src/backups.rs b/src/backups.rs index 68f37ea..4d6ee8e 100644 --- a/src/backups.rs +++ b/src/backups.rs @@ -1,3 +1,6 @@ +//! Backup config and its history. +//! + use core::panic; use std::{ collections::HashMap, @@ -11,7 +14,7 @@ use serde::{Deserialize, Serialize}; use crate::{ devices::Device, - storages::{self, Storage, StorageExt, Storages}, + storages::{StorageExt, Storages}, }; /// Directory to store backup configs for each devices. @@ -26,7 +29,7 @@ pub fn backups_file(device: &Device) -> PathBuf { /// Targets for backup source or destination. #[derive(Debug, Serialize, Deserialize)] pub struct BackupTarget { - /// `name()` of [`Storage`]. + /// `name()` of [`crate::storages::Storage`]. /// Use `String` for serialization/deserialization. pub storage: String, /// Relative path to the `storage`. diff --git a/src/cmd_backup.rs b/src/cmd_backup.rs index ff51461..fc2c08d 100644 --- a/src/cmd_backup.rs +++ b/src/cmd_backup.rs @@ -1,7 +1,7 @@ use std::{ collections::HashMap, io::{self, stdout, Write}, - path::{self, PathBuf}, + path::{ PathBuf}, }; use anyhow::{anyhow, Context, Ok, Result}; diff --git a/src/cmd_init.rs b/src/cmd_init.rs index 585dcbf..b4f4b6f 100644 --- a/src/cmd_init.rs +++ b/src/cmd_init.rs @@ -1,7 +1,7 @@ //! Init subcommand. //! Initialize xdbm for the device. -use crate::backups::{backups_file, Backups}; +use crate::backups::Backups; use crate::storages::{Storages, STORAGESFILE}; use crate::{ add_and_commit, backups, full_status, get_devices, write_devices, Device, DEVICESFILE, diff --git a/src/cmd_storage.rs b/src/cmd_storage.rs index e8c4fa4..f59bb03 100644 --- a/src/cmd_storage.rs +++ b/src/cmd_storage.rs @@ -14,13 +14,12 @@ use unicode_width::{self, UnicodeWidthStr}; use crate::{ add_and_commit, - cmd_args::{Cli, StorageAddCommands}, + cmd_args::StorageAddCommands, devices::{self, Device}, - inquire_filepath_completer::FilePathCompleter, storages::{ self, directory, local_info, physical_drive_partition::{self, PhysicalDrivePartition}, - Storage, StorageExt, StorageType, Storages, + Storage, StorageExt, Storages, }, util, }; diff --git a/src/main.rs b/src/main.rs index 7f4c882..2367aff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,29 +1,28 @@ //! # Main types //! * [Device]: represents PC. module [devices] -//! * [Storage]: all storages. module [storages] -//! * [physical_drive_partition::PhysicalDrivePartition]: partition on a physical disk. module [storages::physical_drive_partition] -//! * [directory::Directory]: sub-directory of other storages. module [storages::directory] -//! * [online_storage::OnlineStorage]: online storage like Google Drive. module [storages::online_storage] -//! * [storages::local_info::LocalInfo]: stores [Device] specific common data for [Storage]s. -//! +//! * [storages::Storage]: all storages. module [storages] +//! * [storages::physical_drive_partition::PhysicalDrivePartition]: partition on a physical disk. module [storages::physical_drive_partition] +//! * [storages::directory::Directory]: sub-directory of other storages. module [storages::directory] +//! * [storages::online_storage::OnlineStorage]: online storage like Google Drive. module [storages::online_storage] +//! * [storages::Storages] for list of [storages::Storage] +//! * [storages::local_info::LocalInfo]: stores [Device] specific common data for [storages::Storage]s. +//! * [backups::Backup] for backup configuration and its logs. +//! * [backups::BackupTarget] source and destination +//! * [backups::BackupLog] backup log #[macro_use] extern crate log; extern crate dirs; -use anyhow::{anyhow, Context, Result}; -use clap::{CommandFactory, Parser}; +use anyhow::{Context, Result}; +use clap::Parser; use git2::{Commit, Oid, Repository}; use std::path::Path; use std::path::{self, PathBuf}; use storages::Storages; use crate::cmd_args::{BackupSubCommands, Cli, Commands, StorageCommands}; -use crate::storages::{ - directory, local_info, online_storage, physical_drive_partition, Storage, StorageExt, - StorageType, STORAGESFILE, -}; use devices::{Device, DEVICESFILE, *}; mod backups; diff --git a/src/storages.rs b/src/storages.rs index d4a0793..d982a3a 100644 --- a/src/storages.rs +++ b/src/storages.rs @@ -1,9 +1,10 @@ //! Manipulates storages. -use crate::storages::directory::Directory; -use crate::storages::online_storage::OnlineStorage; -use crate::storages::physical_drive_partition::PhysicalDrivePartition; -use crate::{devices, storages}; +use crate::devices; +use crate::storages::{ + directory::Directory, online_storage::OnlineStorage, + physical_drive_partition::PhysicalDrivePartition, +}; use anyhow::{anyhow, Context, Result}; use clap::ValueEnum; use core::panic; diff --git a/src/storages/local_info.rs b/src/storages/local_info.rs index 1e4b89e..f645490 100644 --- a/src/storages/local_info.rs +++ b/src/storages/local_info.rs @@ -1,7 +1,7 @@ //! Device specific common data for storages. use serde::{Deserialize, Serialize}; -use std::path::{self, PathBuf}; +use std::path::PathBuf; /// Store local (device-specific) information /// @@ -10,11 +10,11 @@ use std::path::{self, PathBuf}; #[derive(Serialize, Deserialize, Debug)] pub struct LocalInfo { alias: String, - mount_path: path::PathBuf, + mount_path: PathBuf, } impl LocalInfo { - pub fn new(alias: String, mount_path: path::PathBuf) -> LocalInfo { + pub fn new(alias: String, mount_path: PathBuf) -> LocalInfo { LocalInfo { alias, mount_path } } @@ -22,7 +22,7 @@ impl LocalInfo { self.alias.clone() // ? } - pub fn mount_path(&self) -> path::PathBuf { + pub fn mount_path(&self) -> PathBuf { self.mount_path.clone() } } diff --git a/src/storages/online_storage.rs b/src/storages/online_storage.rs index 746e669..8ffafde 100644 --- a/src/storages/online_storage.rs +++ b/src/storages/online_storage.rs @@ -87,7 +87,7 @@ impl StorageExt for OnlineStorage { Ok(()) } - fn parent(&self, storages: &Storages) -> Option<&Storage> { + fn parent(&self, _storages: &Storages) -> Option<&Storage> { None } } diff --git a/src/storages/physical_drive_partition.rs b/src/storages/physical_drive_partition.rs index e410d3f..4a110a6 100644 --- a/src/storages/physical_drive_partition.rs +++ b/src/storages/physical_drive_partition.rs @@ -165,7 +165,7 @@ impl StorageExt for PhysicalDrivePartition { Ok(()) } - fn parent(&self, storages: &Storages) -> Option<&Storage> { + fn parent(&self, _storages: &Storages) -> Option<&Storage> { None } } diff --git a/tests/cli.rs b/tests/cli.rs index c78d6ec..ca0c3cd 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,8 +1,8 @@ mod cmd_init { use std::fs::DirBuilder; - use anyhow::{anyhow, Ok, Result}; - use assert_cmd::{assert::OutputAssertExt, cargo::CommandCargoExt, Command}; + use anyhow::{Ok, Result}; + use assert_cmd::{assert::OutputAssertExt, Command}; use git2::Repository; use log::trace; use predicates::prelude::predicate;