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 void set_script(const std::string &script)
28 { backup_script = script; }
29 RemoteFile *alloc_file(const std::string &name);
30 void enqueue(RemoteFile *file);
38 std::string staging_dir, backup_script;
39 bool terminate; // Set when thread should shut down
40 bool busy; // True while there are pending transfers
41 std::list<RemoteFile *> transfer_queue;
43 /* For error-checking purposes, track the number of files which have been
44 * allocated but not yet queued to be sent. This should be zero when the
45 * RemoteStore is destroyed. */
46 int files_outstanding;
48 void transfer_thread();
49 static void *start_transfer_thread(void *arg);
54 /* Get the file descriptor for writing to the (staging copy of the) file.
55 * The _caller_ is responsible for closing this file descriptor once all
56 * data is written, and before send() is called. */
57 int get_fd() const { return fd; }
59 const std::string &get_local_path() const { return local_path; }
61 /* Called when the file is finished--request that it be sent to the remote
62 * server. This will delete the RemoteFile object. */
63 void send() { remote_store->enqueue(this); }
65 friend class RemoteStore;
67 RemoteFile(RemoteStore *remote,
68 const std::string &name, const std::string &local_path);
70 RemoteStore *remote_store;
73 std::string local_path;
74 std::string remote_path;
77 #endif // _LBS_REMOTE_H