Show
Ignore:
Timestamp:
05/23/07 15:42:00 (6 years ago)
Author:
iacopo <iacopo@…>
Children:
af0cc3aa37cdfc89dbbf6a332d86b7cdf0b97349
Parents:
f81f94e27ada73ae0989c79e9aaee7b8a3952626
git-committer:
iacopo <iacopo@…> (05/23/07 15:42:00)
Message:

Home directory backup and tar with new policy.
Security check do actions only if home dir starts with "/home"

git-svn-id:  https://labs.truelite.it/svn/octofuss/trunk@345 5a101938-5c21-0410-9b5a-a83d6f3706a9

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lib/octofuss/users/__init__.py

    r55cb0ff ra0262d6  
    18761876                #Remove home directory and save it /var/backups 
    18771877                #Create backup 
    1878                 # FIXME!!! the user home directory is a user attribute!  
    1879                 home = "/home" 
    1880                 dir = os.path.join(home,username) 
    1881                 backup = "/var/backups" 
    1882                 fileBackup = os.path.join(backup,username) 
    1883                 try: 
    1884                         now = datetime.datetime.now() 
    1885                         stringTime = now.strftime("%Y%m%d%h%m%S") 
    1886                         r = os.system("tar cvzf "+fileBackup+"_"+stringTime+".tar.gz "+ dir) 
    1887                         if r == 0: 
    1888                             try: 
    1889                                     r = os.system("rm -rf "+dir)  
    1890                             except: 
    1891                                     print "Problems removing "+username+"'s home directory!" 
    1892                                     return 
    1893                 except: 
    1894                         print "Problems saving "+username+"'s home directory!" 
    1895  
    1896                  
    1897  
    1898  
     1878                home = userObj.getHome().getValue() 
     1879                 
     1880                if home and home.startswith("/home/"): 
     1881                        try: 
     1882                                now = datetime.datetime.now() 
     1883                                stringTime = now.strftime("%Y%m%d%h%m%S") 
     1884                                #Security check 
     1885                                # Do all action only if /home direcotry starts with /home 
     1886                                if home.endswith("/"): 
     1887                                        fileBackup = home[0:-1] + "-" + stringTime + ".bck" 
     1888                                else: 
     1889                                        fileBackup = home + "-" + stringTime + ".bck" 
     1890                                print fileBackup  
     1891                                compress = self.dialogYesNo("Home backup in process\nDo you want to compress the backup and remove home directory?") 
     1892                                if compress == -8: 
     1893                                        #Compress 
     1894                                        fileBackup = fileBackup+".tar.gz"  
     1895                                        r = os.system("tar cvzf "+fileBackup+" "+home)  
     1896                                        #Remove original 
     1897                                        if r == 0: 
     1898                                                r = os.system("rm -rf "+home)     
     1899                                                if r != 0: 
     1900                                                        raise Exception("Could not delete home directory after compression.") 
     1901 
     1902                                        else: 
     1903                                                raise Exception("Could not compress and delete home directory!\nTry without compress it.") 
     1904                                elif compress == -9: 
     1905                                        #Rename 
     1906                                        r = os.rename(home,fileBackup) 
     1907                                if r != 0 and r != None: 
     1908                                        raise Exception 
     1909                                else: 
     1910                                        showDialog("Backup done: "+fileBackup, gtk.MESSAGE_INFO) 
     1911                        except Exception,e: 
     1912                                print e 
     1913                                showDialog("Problems doing backup of "+username+"'s home directory!",gtk.MESSAGE_ERROR) 
     1914                else: 
     1915                        print "Home doesn't exist" 
     1916 
     1917                 
     1918 
     1919 
     1920        def dialogYesNo(self, message): 
     1921                dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_YES_NO,message ) 
     1922                dialog.show() 
     1923                # Close dialog on user response 
     1924                resp = dialog.run() 
     1925                dialog.destroy() 
     1926                return resp 
    18991927 
    19001928