-/* Cumulus: Smart Filesystem Backup to Dumb Servers
- *
- * Copyright (C) 2008 The Regents of the University of California
- * Written by Michael Vrable <mvrable@cs.ucsd.edu>
+/* 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
* scripts that are called when a file is to be transferred. */
#include <assert.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
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. */
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
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)