Skip to content
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

Closed

Conversation

lbgracioso
Copy link
Collaborator

@lbgracioso lbgracioso commented Apr 5, 2024

This PR adds the current timestamp (ISO 8601 like) to the end of the backup file names

Example: Created a backup copy of /etc/exports on /opt/cloysterhpc/backup/etc/exports_2024-06-19T11:08:45Z

@lbgracioso lbgracioso added the enhancement New feature or request label Apr 5, 2024
Copy link

sonarcloud bot commented Apr 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link
Owner

@viniciusferrao viniciusferrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this idea is very good, but I would suggest to stick with standards like ISO 8601 with is supported directly on the language.

I've added comments directly on the code to address those issues.

src/functions.cpp Outdated Show resolved Hide resolved
src/functions.cpp Outdated Show resolved Hide resolved
@viniciusferrao
Copy link
Owner

Hi @lbgracioso did you took a chance to look at the comments on this one?

@lbgracioso
Copy link
Collaborator Author

@viniciusferrao Can you please check it again?

* \brief Get the current timestamp as a string.
*
* This function generates the current timestamp in the format
* "YYYYMMDD_HHMMSS".
Copy link
Owner

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.

time_t now;
time(&now);
char buf[sizeof "2011-10-08T07:07:09Z"];
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use chrono instead?

strftime is a C directive that's available on ctime and we should definitely avoid using legacy C functions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this can be done with chrono
https://en.cppreference.com/w/cpp/chrono

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use stringstream if using chrono. Already discussed with @viniciusferrao

Copy link
Owner

Choose a reason for hiding this comment

The 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 stringstream because it sucks and we have std::format now, however we just need to find a way to use it with chrono.

@arthurmco
Copy link
Collaborator

Dropping it because #64 is already merged.

@arthurmco arthurmco closed this Jul 24, 2024
@viniciusferrao
Copy link
Owner

I've merged wrong @arthurmco?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants