You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
816 B
31 lines
816 B
''' |
|
Chronological file backup example |
|
''' |
|
|
|
import datetime |
|
import time |
|
|
|
#to generate a date: |
|
#x=datetime.datetime.now().strftime('%Y-%m-%d') |
|
|
|
#Sample dates |
|
DATES = ['2021-01-07', '2021-02-14', '2021-06-22', |
|
'2021-04-14', '2021-03-19', '2021-07-11', '2021-05-14'] |
|
|
|
#sample file names |
|
FNAMES = ['SP_dryad_production.sqlite3.'+ x for x in DATES] |
|
|
|
#Note: min max etc work on dictionary keys |
|
#datetime.datetime(*(time.strptime(y, '%Y-%m-%d %H:%M:%S')[0:6]))#painful |
|
#see https://python.readthedocs.io/en/latest/library/datetime.html |
|
|
|
FNAME_D={datetime.datetime( |
|
*(time.strptime(dat[-10:],'%Y-%m-%d')[0:6])): dat |
|
for dat in FNAMES} |
|
TIMES = list(FNAME_D) |
|
TIMES.sort() |
|
#There can be only 3 |
|
for fil in TIMES[3:]: |
|
print(f'os.remove({FNAME_D[fil]})') |
|
del FNAMES[FNAMES.index(FNAME_D[fil])] |
|
print(FNAMES)
|
|
|