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

added new datetime_from_dir() function to parse BackInTime folder names #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdhoney
Copy link

@mdhoney mdhoney commented Feb 1, 2022

Back In Time uses rsync+hardlinks, but (on my machine at least) the timestamps get messed up sometimes, so I needed a more reliable way of getting the original timestamp from the directory name (e.g. 20200428-170001-777). It's mostly just adjusting the strptime format, as well as converting the time to UTC (since the folder times are in local time).
To actually use this, a small change in rsynchl.py will be required.

@mdhoney
Copy link
Author

mdhoney commented Feb 1, 2022

I didn't realize that committing to my branch after initiating the PR would add these changes too. Hence the force-push in order to reset to previous commit.

returns a datetime object if the format could be parsed.
raises ValueError if not.
"""
if type(d).__name__ == 'PosixPath':
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rather:

if isinstance(d, Path):

returns a datetime object if the format could be parsed.
raises ValueError if not.
"""
if type(d).__name__ == 'PosixPath':
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rather:

if isinstance(d, Path):

"""
if type(d).__name__ == 'PosixPath':
s = d.name
elif type(d) == str:
Copy link
Member

Choose a reason for hiding this comment

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

similar here.

"""
if type(d).__name__ == 'PosixPath':
s = d.name
elif type(d) == str:
Copy link
Member

Choose a reason for hiding this comment

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

similar here.

Comment on lines +56 to +57
# get rid of trailing -??? numbers that BackInTime adds
s = s[:-p].strip()
Copy link
Member

Choose a reason for hiding this comment

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

if it is always "dash digits" you could also use s.rsplit('-', 1).

Comment on lines +56 to +57
# get rid of trailing -??? numbers that BackInTime adds
s = s[:-p].strip()
Copy link
Member

Choose a reason for hiding this comment

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

if it is always "dash digits" you could also use s.rsplit('-', 1).

Comment on lines +63 to +66
dt = datetime.strptime(s, ts_format)
# adjust time zone offset to get UTC
tz = int(time.strftime('%z')[:-2])
ut = dt - timedelta(hours=tz)
Copy link
Member

Choose a reason for hiding this comment

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

maybe reading the docs again gives a better way here. :-)

Comment on lines +63 to +66
dt = datetime.strptime(s, ts_format)
# adjust time zone offset to get UTC
tz = int(time.strftime('%z')[:-2])
ut = dt - timedelta(hours=tz)
Copy link
Member

Choose a reason for hiding this comment

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

maybe reading the docs again gives a better way here. :-)

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

Successfully merging this pull request may close these issues.

2 participants