| 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 |