add backup/restore functionality
This commit is contained in:
parent
44fff79e61
commit
4af68c3d9a
48
do_what.py
48
do_what.py
@ -4,6 +4,7 @@ import subprocess
|
||||
import configparser
|
||||
import magic
|
||||
import json
|
||||
import datetime
|
||||
|
||||
mime = magic.Magic(mime=True)
|
||||
|
||||
@ -213,6 +214,53 @@ elif ( active and len(sys.argv) > argiter+1 and sys.argv[argiter+1] == 'p' ):
|
||||
|
||||
exit()
|
||||
|
||||
# File/Directory backup creator
|
||||
# Capital B = Time versioned backup
|
||||
elif ( active and len(sys.argv) > argiter+1 and sys.argv[argiter+1] == 'B' ):
|
||||
if ( filearg == '-' ):
|
||||
print("No file/directory specified to backup.")
|
||||
elif ( os.path.isfile( path ) ):
|
||||
bakname = ".bak-"+datetime.datetime.now().strftime("%Y-%B-%d_%I:%M%p")
|
||||
print("cp "+path+" "+path+bakname)
|
||||
print("echo Created file backup: "+path+bakname)
|
||||
elif( os.path.isdir( path ) ):
|
||||
bakname = ".bak-"+datetime.datetime.now().strftime("%Y-%B-%d_%I:%M%p")
|
||||
print("cp -r "+path+" "+path+bakname)
|
||||
print("echo Created directory backup: "+path+bakname)
|
||||
exit()
|
||||
# Lowercase b = un-versioned backup
|
||||
elif ( active and len(sys.argv) > argiter+1 and sys.argv[argiter+1] == 'b' ):
|
||||
if ( filearg == '-' ):
|
||||
print("No file/directory specified to backup.")
|
||||
elif ( os.path.isfile( path ) ):
|
||||
bakname = ".bak"
|
||||
print("cp "+path+" "+path+bakname)
|
||||
print("echo Created file backup: "+path+bakname)
|
||||
elif( os.path.isdir( path ) ):
|
||||
bakname = ".bak"
|
||||
print("cp -r "+path+" "+path+bakname)
|
||||
print("echo Created directory backup: "+path+bakname)
|
||||
exit()
|
||||
# Lowercase r = restore the specified backup
|
||||
elif ( active and len(sys.argv) > argiter+1 and sys.argv[argiter+1] == 'r' ):
|
||||
if ( filearg == '-' ):
|
||||
print("No file/directory specified to restore.")
|
||||
elif ( os.path.isfile( path ) ):
|
||||
if ( ".bak" not in path ):
|
||||
print("echo "+path+" is not a valid backup file.")
|
||||
else:
|
||||
restorepath = path.split(".bak", 1)[0]
|
||||
print("mv "+path+" "+restorepath)
|
||||
print("echo Restored file: "+restorepath)
|
||||
elif ( os.path.isdir( path ) ):
|
||||
if ( ".bak" not in path ):
|
||||
print("echo "+path+" is not a valid backup directory.")
|
||||
else:
|
||||
restorepath = path.split(".bak", 1)[0]
|
||||
print("mv "+path+" "+restorepath)
|
||||
print("echo Restored directory: "+restorepath)
|
||||
exit()
|
||||
|
||||
# File Operations
|
||||
if ( (not active and len(sys.argv) == 1) or (active and len(sys.argv) == 2) ):
|
||||
# list the contents of the current directory
|
||||
|
Loading…
Reference in New Issue
Block a user