1 /* LBS: An LFS-inspired filesystem backup system
2 * Copyright (C) 2006 Michael Vrable
4 * Backup data (segments and backup descriptors) may be stored on a remote
5 * fileserver instead of locally. The only local storage needed is for the
6 * local database and some temporary space for staging files before they are
7 * transferred to the remote server.
9 * Like encryption, remote storage is handled through the use of external
10 * scripts that are called when a file is to be transferred. */
23 static const size_t MAX_QUEUE_SIZE = 4;
25 RemoteStore(const std::string &stagedir);
27 RemoteFile *alloc_file(const std::string &name);
28 void enqueue(RemoteFile *file);
36 std::string staging_dir;
37 bool terminate; // Set when thread should shut down
38 bool busy; // True while there are pending transfers
39 std::list<RemoteFile *> transfer_queue;
41 /* For error-checking purposes, track the number of files which have been
42 * allocated but not yet queued to be sent. This should be zero when the
43 * RemoteStore is destroyed. */
44 int files_outstanding;
46 void transfer_thread();
47 static void *start_transfer_thread(void *arg);
52 /* Get the file descriptor for writing to the (staging copy of the) file.
53 * The _caller_ is responsible for closing this file descriptor once all
54 * data is written, and before send() is called. */
55 int get_fd() const { return fd; }
57 const std::string &get_local_path() const { return local_path; }
59 /* Called when the file is finished--request that it be sent to the remote
60 * server. This will delete the RemoteFile object. */
61 void send() { remote_store->enqueue(this); }
63 friend class RemoteStore;
65 RemoteFile(RemoteStore *remote,
66 const std::string &name, const std::string &local_path);
68 RemoteStore *remote_store;
71 std::string local_path;
72 std::string remote_path;
75 #endif // _LBS_REMOTE_H