-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timestamp on backup files #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,10 +141,28 @@ void removeFile(std::string_view filename) | |
} | ||
} | ||
|
||
/** | ||
* \brief Get the current timestamp as a string. | ||
* | ||
* This function generates the current timestamp in the format | ||
* "YYYYMMDD_HHMMSS". | ||
* | ||
* \return A string with the current timestamp. | ||
*/ | ||
std::string getCurrentTimestamp() | ||
{ | ||
time_t now; | ||
time(&now); | ||
char buf[sizeof "2011-10-08T07:07:09Z"]; | ||
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this can be done with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to use stringstream if using chrono. Already discussed with @viniciusferrao There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The beautiful thing of C++ is the legacy that we have. There's probably a way to completely ditch |
||
return buf; | ||
} | ||
|
||
/* Backup file */ | ||
void backupFile(std::string_view filename) | ||
{ | ||
const auto& backupFile = fmt::format("{}/backup{}", installPath, filename); | ||
const auto& backupFile = fmt::format( | ||
"{}/backup{}_{}", installPath, filename, getCurrentTimestamp()); | ||
|
||
if (cloyster::dryRun) { | ||
LOG_INFO( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs needs to be also updated.