-/* LBS: An LFS-inspired filesystem backup system
- * Copyright (C) 2006 Michael Vrable
+/* Cumulus: Smart Filesystem Backup to Dumb Servers
*
- * Backup data (segments and backup descriptors) may be stored on a remote
+ * Copyright (C) 2008 The Regents of the University of California
+ * Written by Michael Vrable <mvrable@cs.ucsd.edu>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Backup data (segments and backup descriptors) may be stored on a remote
* fileserver instead of locally. The only local storage needed is for the
* local database and some temporary space for staging files before they are
* transferred to the remote server.
* will initially be created in a temporary directory. When the file is
* written out, the RemoteFile object should be passed to RemoteStore::enqueue,
* which will upload it to the remote server. */
-RemoteFile *RemoteStore::alloc_file(const string &name)
+RemoteFile *RemoteStore::alloc_file(const string &name, const string &type)
{
- fprintf(stderr, "Allocate file: %s\n", name.c_str());
pthread_mutex_lock(&lock);
files_outstanding++;
pthread_mutex_unlock(&lock);
- return new RemoteFile(this, name, staging_dir + "/" + name);
+ return new RemoteFile(this, name, type, staging_dir + "/" + name);
}
/* Request that a file be transferred to the remote server. The actual
* responsible for its destruction. */
void RemoteStore::enqueue(RemoteFile *file)
{
- fprintf(stderr, "Enqueue: %s\n", file->remote_path.c_str());
-
pthread_mutex_lock(&lock);
while (transfer_queue.size() >= MAX_QUEUE_SIZE)
/* Wait for all transfers to finish. */
void RemoteStore::sync()
{
- fprintf(stderr, "RemoteStore::sync() start\n");
pthread_mutex_lock(&lock);
while (busy)
pthread_cond_wait(&cond, &lock);
pthread_mutex_unlock(&lock);
- fprintf(stderr, "RemoteStore::sync() end\n");
}
void *RemoteStore::start_transfer_thread(void *arg)
pthread_mutex_unlock(&lock);
// Transfer the file
- fprintf(stderr, "Start transfer: %s\n", file->remote_path.c_str());
if (backup_script != "") {
pid_t pid = fork();
if (pid < 0) {
}
if (pid == 0) {
string cmd = backup_script;
- cmd += " " + file->local_path + " " + file->remote_path;
+ cmd += " " + file->local_path + " " + file->type + " "
+ + file->remote_path;
execlp("/bin/sh", "/bin/sh", "-c", cmd.c_str(), NULL);
throw IOException("exec failed");
}
file->local_path.c_str());
}
}
- fprintf(stderr, "Finish transfer: %s\n", file->remote_path.c_str());
delete file;
}
}
RemoteFile::RemoteFile(RemoteStore *remote,
- const string &name, const string &local_path)
+ const string &name, const string &type,
+ const string &local_path)
{
remote_store = remote;
+ this->type = type;
this->local_path = local_path;
this->remote_path = name;