Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active July 25, 2022 13:19
Show Gist options
  • Save rsperl/7e7a69fc6e78577529ae5bc4abbc6178 to your computer and use it in GitHub Desktop.
Save rsperl/7e7a69fc6e78577529ae5bc4abbc6178 to your computer and use it in GitHub Desktop.
backup a file with a timestamp #python #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import shutil
origfile = "myfile.txt"
backupfile = origfile + "." + datetime.now().strftime("%Y-%m-%d_%H%M%S")
shutil.copy(origfile, backupfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment