Mulla ois tässä pieni scripti pythonilla, joka kopioi halutun kansion haluttuun kansioon zipattuna. Sitä voi muokata siten, että sen saa automaattiseksi, ettei se kysele mitään, ja saa sen varmastikin käyttämään taria. Pitää ettiä minne sen sais upittua, että voisit kokeilla.
Startupissa voisi laittaa esim. Istuntojen mukana käynnistyviin tehtäviin tai vastaavaa.
No pistän sen tähän kuitenkin:
#!/usr/bin/python
# Filename: backup.txt
# This code was made by Regel Argoy for his personal use.
import os
import time
from time import sleep
import sys
x = 1
p = 1
k = 'p'
if len(sys.argv) < 2:
# What do u wanna back up?
while x != 0:
a = input("""What directory do you want to back up?
\n 1 /home/regel/
\n 2 /home/regel/koulu
\n 3 /home/regel/tiedostoja
\n 4 Else
\n > """)
if a == 1:
s = '/home/regel'
break
elif a == 2:
s = '/home/regel/koulu'
break
elif a == 3:
s = 'home/regel/tiedostoja'
break
elif a == 4:
s = raw_input("Type in the source directory: \n > ")
if not os.path.exists(s):
print "No such file or directory."
sleep(1)
continue
else:
break
else:
print "That's not a valid option, choose again."
sleep(1)
continue
source = [s]
# Wanna back up something else?
while p != 0:
g = raw_input("Do you want to backup something else? (y/n) \n > ")
if g == 'y':
if k == 'n':
break
else:
c = raw_input("What directory do you want to back up? \n > ")
if not os.path.exists(c):
print "No such file or directory."
sleep(1)
continue
else:
source.append(c)
while x != 0:
k = raw_input("Something else (y/n)? \n > ")
if k == 'y':
break
elif k == 'n':
break
else:
print "That's not a valid option, choose again."
sleep(1)
continue
elif g == 'n':
print "Ok \n"
break
else:
print "That's not a valid option, choose again."
sleep(1)
continue
# Target directory
while x != 0:
q = input("""What is the target directory?
\n 1 /media/yhteinen/backups/
\n 2 /media/sda1/
\n 3 Else
\n > """)
if q == 1:
t = '/media/yhteinen/backups/'
break
elif q == 2:
t = '/media/sda1/'
break
elif q == 3:
while x != 0:
t = raw_input("Type in the target directory: \n > ")
if not os.path.exists(t):
print "No such file or directory."
sleep(1)
continue
else:
break
break
else:
print "That's not a valid option, choose again."
sleep(1)
continue
target_dir = t
target = target_dir + 'backup_' + time.strftime('%d%m%Y%H%M') + '.zip'
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# "Are you sure?"
print "These directories/files will be backed up: \n"
for item in source:
print item
print "\nThis is the target directory: \n", target_dir
while x != 0:
varmistus = raw_input("\nContinue? (y/n): \n > ")
if varmistus == 'y':
if os.system(zip_command) == 0:
print 'Succesful backup to', target
else:
print 'Backup FAILED!'
break
elif varmistus == 'n':
print "Backup aborted"
break
else:
print "That's not a valid option, please choose again."
sleep(1)
else:
if sys.argv[1].startswith('--'):
option = sys.argv[1][2:]
# fetch sys.argv[1] but without the first two characters
if option == 'version':
print 'Version 1.2'
elif option == 'info':
print 'Code by : Regel Argoy \nContact : janne_solanpaa@hotmail.com \nDepends on python'
elif option == 'help':
print '''\
This script makes a backup of specified files/directories.
Any number of directories/files can be specified.
Options include:
--version : Prints the version number
--help : Display this help
--info : Show info about Regel, the maker '''
else:
print 'Unknown option.'
sys.exit()
Modet editoikoon jos haluavat.