Skip to content

Syncing ..cntd #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all 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
49 changes: 36 additions & 13 deletions aw-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use aw_client_rust::AwClient;
mod accessmethod;
mod sync;

const DEFAULT_PORT: &str = "5600";

#[derive(Parser)]
#[clap(version = "0.1", author = "Erik Bjäreholt")]
struct Opts {
Expand All @@ -36,15 +34,22 @@ struct Opts {
#[clap(long, default_value = "127.0.0.1")]
host: String,
/// Port of instance to connect to.
#[clap(long, default_value = DEFAULT_PORT)]
#[clap(long, default_value = "5600")]
port: String,
/// Convenience option for using the default testing host and port.
#[clap(long)]
testing: bool,
/// Path to sync directory.
/// Path to sync directory, which is setup with 3rd party syncing service(eg. Dropbox etc.)
/// If not specified, exit.
#[clap(long)]
sync_dir: String,
/// Path to sync staging directory, which will be used for staging.
/// Default (..)/aw-server-rust/aw-sync/staging/ will be used.
#[clap(long)]
sync_stg_dir: String,
/// Sync adaptor to use
#[clap(long, default_value = "file")]
sync_adp: String,
}

#[derive(Subcommand)]
Expand All @@ -57,12 +62,32 @@ enum Commands {
#[clap(arg_required_else_help = true)]
Sync {
/// Date to start syncing from.
/// If not specified, start from beginning.
/// If not specified, starts from beginning.
/// NOTE: might be unstable, as count cannot be used to verify integrity of sync.
/// Format: YYYY-MM-DD
#[clap(long)]
start_date: Option<String>,
/// Specify buckets to sync using a comma-separated list.
/// Specify bucket names to sync using a comma-separated list.
/// If not specified, all buckets will be synced.
#[clap(long)]
buckets: Option<String>,
/// Mode to sync in. Can be "push", "pull", or "both".
/// Defaults to "both".
#[clap(long, default_value = "both")]
mode: String,
},
/// Run subcommand.
///
/// Pulls remote buckets, pushes local buckets periodically.
/// from/to sync_dir
Run {
/// Date to start syncing from.
/// If not specified, starts from beginning.
/// NOTE: might be unstable, as count cannot be used to verify integrity of sync.
/// Format: YYYY-MM-DD
#[clap(long)]
start_date: Option<String>,
/// Specify bucket names to sync using a comma-separated list.
/// If not specified, all buckets will be synced.
#[clap(long)]
buckets: Option<String>,
Expand All @@ -78,10 +103,12 @@ enum Commands {
fn main() -> Result<(), Box<dyn Error>> {
let opts: Opts = Opts::parse();

info!("Started aw-sync...");

aw_server::logging::setup_logger(true).expect("Failed to setup logging");
info!("Started aw-sync...");

if opts.testing {
info!("Running in Testing mode...")
}
let sync_directory = if opts.sync_dir.is_empty() {
println!("No sync directory specified, exiting...");
std::process::exit(1);
Expand All @@ -90,11 +117,7 @@ fn main() -> Result<(), Box<dyn Error>> {
};
info!("Using sync dir: {}", sync_directory.display());

let port = if opts.testing && opts.port == DEFAULT_PORT {
"5666"
} else {
&opts.port
};
let port = if opts.testing { "5666" } else { &opts.port };

let client = AwClient::new(opts.host.as_str(), port, "aw-sync");

Expand Down