Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (2)

Powered by Vanilla. Made with Bootstrap.
BackTar
  • chroniccommand
    Posts: 1,389
    Here is a simple script I wrote to perform some backup by tar'ing files up. Enjoy.

    #!/usr/bin/python
    #Backup.py
    #Written by Chroniccommand to stop Wezo from bitching about the size of Duplicity
    '''
    Documentation: RTFM!
    This script simply tars up a directory. Tar means compress, so it will compress all the files into a simple tar file.
    To restore, untar the file and mv the files to where they're supposed to go.
    Example:
    backtar /home/chronic /mnt/external
    '''
    import sys, os, datetime

    def usage():
    print(\"Usage:\n%s </file/to/backup/> </path/to/backup/to>\" % sys.argv[0])
    sys.exit()

    if len(sys.argv) != 3:
    usage()

    def backup(backfile, path):
    curdate = datetime.datetime.now()
    filename = curdate.strftime(\"%Y-%m-%d%H%M\")
    print(\"Backing up. Please wait....\")
    backfilename = \"backup-%s\" % filename
    tar = (\"tar -zcf %s %s\" % (backfilename, path))
    os.system(tar)
    mv = (\"mv %s %s\" % (backfilename, path))
    os.system(mv)
    print(\"Backup complete\")
    sys.exit()

    backfile = sys.argv[1]
    path = sys.argv[2]
    backup(backfile, path)


    GUI version using wxPython

    #!/usr/bin/python
    #Backup.py
    #Written by Chroniccommand to stop Wezo from bitching about the size of Duplicity
    '''
    Documentation: RTFM!
    This script simply tars up a directory. Tar means compress, so it will compress all the files into a simple tar file.
    To restore, untar the file and mv the files to where they're supposed to go.
    This version is GUI using wxPython
    '''
    import sys, os, datetime
    try:
    import wx
    except ImportError:
    print(\"wxPython module not found! This is required\")
    sys.exit()
    class frame(wx.Frame):
    def __init__(self, parent, id):
    wx.Frame.__init__(self,parent,id,'BackTar GUI', size=(300, 200))
    panel = wx.Panel(self)
    box = wx.TextEntryDialog(None, \"Path to backup\", \"BackTar GUI\", \"\")
    if box.ShowModal() == wx.ID_OK:
    backfile = box.GetValue()
    print backfile
    box2 = wx.TextEntryDialog(None, \"Path to backup to\", \"BackTar GUI\", \"\")
    if box2.ShowModal() == wx.ID_OK:
    path = box2.GetValue()
    print path
    wx.MessageBox('Backing up. Please wait(Press OK to continue)....', 'Info')
    print(\"Message from system: Please wait. Backing up....\")
    self.backup(backfile, path)
    def backup(self, backfile, path):
    global entry
    curdate = datetime.datetime.now()
    filename = curdate.strftime(\"%Y-%m-%d%H%M\")
    print(\"Backing up. Please wait....\")
    backfilename = \"backup-%s\" % filename
    tar = (\"tar -zcf %s %s\" % (backfilename, path))
    os.system(tar)
    mv = (\"mv %s %s\" % (backfilename, path))
    os.system(mv)
    print(\"Backup complete\")
    sys.exit()
    app = wx.PySimpleApp()
    frame = frame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()
  • s1n4
    Posts: 88
    Nice, Thanks chroniccommand :)
  • Xin
    Posts: 3,251
    Nice , although it would probably be easier just doing it manually :p
    Xin
  • chroniccommand
    Posts: 1,389
    said:


    Nice , although it would probably be easier just doing it manually :p



    I like to write nifty scripts like this in my spare time. Plus somebody on a different site was bitching about other backup software being 80 MB so I wrote it to make him stop complaining lol.