Last active
December 27, 2015 00:59
-
-
Save Nama/7242107 to your computer and use it in GitHub Desktop.
Deleting of incoming and outdated SQL backups.
Using with crontab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#Deleting of incoming and outdated SQL backups - Using with crontab | |
import os, re | |
d_list = sorted( #Filenames containing unix-timestamp, sorted() will set 'd_list' ordered, from old to new | |
re.findall(r'\w+\.sql\.gz', #searching for filenames | |
','.join(os.listdir('/home/kirika')))) #Listing all files in directory and putting them comma-seperated together | |
for i in range(len(d_list)-4): #Count of found files -4 | |
os.remove(d_list[i]) #the newest 4 files wont be deleted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment