X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=blobdiff_plain;f=remote.cc;h=e8e046eb5f5bb72da0569ef7b06cc23f71deaabf;hp=5a20c2301cb026fefbeccb6bfbaef2b11d22e41b;hb=HEAD;hpb=65edb87a0b8a578b4a7221478a851d71df21fab0 diff --git a/remote.cc b/remote.cc index 5a20c23..e8e046e 100644 --- a/remote.cc +++ b/remote.cc @@ -1,7 +1,6 @@ -/* Cumulus: Smart Filesystem Backup to Dumb Servers - * - * Copyright (C) 2008 The Regents of the University of California - * Written by Michael Vrable +/* Cumulus: Efficient Filesystem Backup to the Cloud + * Copyright (C) 2008-2009 The Cumulus Developers + * See the AUTHORS file for a list of contributors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +26,7 @@ * scripts that are called when a file is to be transferred. */ #include +#include #include #include #include @@ -45,11 +45,32 @@ using std::string; +static const char *backup_directories[] = { + "meta", + "segments0", + "segments1", + "snapshots", + NULL +}; + RemoteStore::RemoteStore(const string &stagedir, const string &script) { staging_dir = stagedir; backup_script = script; + /* Ensure all necessary directories exist for each type of backup file. */ + for (size_t i = 0; backup_directories[i]; i++) { + string path = stagedir + "/" + backup_directories[i]; + if (mkdir(path.c_str(), 0777) < 0) { + /* Ignore errors for already-existing directories. */ + if (errno != EEXIST) { + fprintf(stderr, + "Warning: Cannot create backup directory %s: %m!", + path.c_str()); + } + } + } + /* A background thread is created for each RemoteStore to manage the actual * transfers to a remote server. The main program thread can enqueue * RemoteFile objects to be transferred asynchronously. */ @@ -94,7 +115,8 @@ RemoteFile *RemoteStore::alloc_file(const string &name, const string &type) pthread_mutex_lock(&lock); files_outstanding++; pthread_mutex_unlock(&lock); - return new RemoteFile(this, name, type, staging_dir + "/" + name); + return new RemoteFile(this, name, type, + staging_dir + "/" + type + "/" + name); } /* Request that a file be transferred to the remote server. The actual @@ -251,7 +273,7 @@ RemoteFile::RemoteFile(RemoteStore *remote, remote_store = remote; this->type = type; this->local_path = local_path; - this->remote_path = name; + this->remote_path = type + "/" + name; fd = open(local_path.c_str(), O_WRONLY | O_CREAT, 0666); if (fd < 0)