summaryrefslogtreecommitdiff
path: root/lib/backupstore/BackupAccountControl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backupstore/BackupAccountControl.cpp')
-rw-r--r--lib/backupstore/BackupAccountControl.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/lib/backupstore/BackupAccountControl.cpp b/lib/backupstore/BackupAccountControl.cpp
new file mode 100644
index 00000000..6fbbc30e
--- /dev/null
+++ b/lib/backupstore/BackupAccountControl.cpp
@@ -0,0 +1,131 @@
+// --------------------------------------------------------------------------
+//
+// File
+// Name: BackupAccountControl.cpp
+// Purpose: Client-side account management for Amazon S3 stores
+// Created: 2015/06/27
+//
+// --------------------------------------------------------------------------
+
+#include "Box.h"
+
+#include <climits>
+#include <iostream>
+
+#include "BackupAccountControl.h"
+#include "BackupStoreInfo.h"
+#include "Configuration.h"
+
+#include "MemLeakFindOn.h"
+
+void BackupAccountControl::CheckSoftHardLimits(int64_t SoftLimit, int64_t HardLimit)
+{
+ if(SoftLimit > HardLimit)
+ {
+ BOX_FATAL("Soft limit must be less than the hard limit.");
+ exit(1);
+ }
+ if(SoftLimit > ((HardLimit * MAX_SOFT_LIMIT_SIZE) / 100))
+ {
+ BOX_WARNING("We recommend setting the soft limit below " <<
+ MAX_SOFT_LIMIT_SIZE << "% of the hard limit, or " <<
+ HumanReadableSize((HardLimit * MAX_SOFT_LIMIT_SIZE)
+ / 100) << " in this case.");
+ }
+}
+
+int64_t BackupAccountControl::SizeStringToBlocks(const char *string, int blockSize)
+{
+ // Get number
+ char *endptr = (char*)string;
+ int64_t number = strtol(string, &endptr, 0);
+ if(endptr == string || number == LONG_MIN || number == LONG_MAX)
+ {
+ BOX_FATAL("'" << string << "' is not a valid number.");
+ exit(1);
+ }
+
+ // Check units
+ switch(*endptr)
+ {
+ case 'M':
+ case 'm':
+ // Units: Mb
+ return (number * 1024*1024) / blockSize;
+ break;
+
+ case 'G':
+ case 'g':
+ // Units: Gb
+ return (number * 1024*1024*1024) / blockSize;
+ break;
+
+ case 'B':
+ case 'b':
+ // Units: Blocks
+ // Easy! Just return the number specified.
+ return number;
+ break;
+
+ default:
+ BOX_FATAL(string << " has an invalid units specifier "
+ "(use B for blocks, M for MB, G for GB, eg 2GB)");
+ exit(1);
+ break;
+ }
+}
+
+std::string BackupAccountControl::BlockSizeToString(int64_t Blocks, int64_t MaxBlocks, int BlockSize)
+{
+ return FormatUsageBar(Blocks, Blocks * BlockSize, MaxBlocks * BlockSize,
+ mMachineReadableOutput);
+}
+
+int BackupAccountControl::PrintAccountInfo(const BackupStoreInfo& info,
+ int BlockSize)
+{
+ // Then print out lots of info
+ std::cout << FormatUsageLineStart("Account ID", mMachineReadableOutput) <<
+ BOX_FORMAT_ACCOUNT(info.GetAccountID()) << std::endl;
+ std::cout << FormatUsageLineStart("Account Name", mMachineReadableOutput) <<
+ info.GetAccountName() << std::endl;
+ std::cout << FormatUsageLineStart("Last object ID", mMachineReadableOutput) <<
+ BOX_FORMAT_OBJECTID(info.GetLastObjectIDUsed()) << std::endl;
+ std::cout << FormatUsageLineStart("Used", mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksUsed(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Current files",
+ mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksInCurrentFiles(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Old files", mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksInOldFiles(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Deleted files", mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksInDeletedFiles(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Directories", mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksInDirectories(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Soft limit", mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksSoftLimit(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Hard limit", mMachineReadableOutput) <<
+ BlockSizeToString(info.GetBlocksHardLimit(),
+ info.GetBlocksHardLimit(), BlockSize) << std::endl;
+ std::cout << FormatUsageLineStart("Client store marker", mMachineReadableOutput) <<
+ info.GetClientStoreMarker() << std::endl;
+ std::cout << FormatUsageLineStart("Current Files", mMachineReadableOutput) <<
+ info.GetNumCurrentFiles() << std::endl;
+ std::cout << FormatUsageLineStart("Old Files", mMachineReadableOutput) <<
+ info.GetNumOldFiles() << std::endl;
+ std::cout << FormatUsageLineStart("Deleted Files", mMachineReadableOutput) <<
+ info.GetNumDeletedFiles() << std::endl;
+ std::cout << FormatUsageLineStart("Directories", mMachineReadableOutput) <<
+ info.GetNumDirectories() << std::endl;
+ std::cout << FormatUsageLineStart("Enabled", mMachineReadableOutput) <<
+ (info.IsAccountEnabled() ? "yes" : "no") << std::endl;
+
+ return 0;
+}
+