Browse Source

better comments pt5

Aiden Holmes 3 months ago
parent
commit
52106dd399
1 changed files with 13 additions and 6 deletions
  1. 13
    6
      backr.py

+ 13
- 6
backr.py View File

@@ -151,11 +151,12 @@ def main():
151 151
     if not os.path.exists(backup_location):
152 152
         os.makedirs(backup_location)
153 153
 
154
-    # cp -r this folder that folder
154
+    # This line does the actual backup, it copies the current directory to the backup location
155 155
     copy_tree(cwd, backup_location)
156 156
 
157
-    # if compression was set to true
158
-        # compress all the files in that folder individually
157
+    # If use_compression was set, make a tarball of the backup
158
+    # Then delete the original backup, then output that folder was backed up
159
+    # Output varies depending on whether or not it was compressed
159 160
     if use_compression:
160 161
         make_tarfile(backbase+"/"+time+".tar.gz", backup_location)
161 162
         shutil.rmtree(backup_location)
@@ -163,8 +164,13 @@ def main():
163 164
     else:
164 165
         print "folder backed up to "+backup_location
165 166
 
166
-    # check for existence for version control file
167
+    # We use a file called backtrack.txt to keep track of how many backups
168
+    # there are and their locations, this is necessary for restor.py
169
+    # It is stored in the backbase, eg ~/backrs/basename-hash
167 170
     vc_file = backbase+"/backtrack.txt"
171
+
172
+    # If the file does not exist we create it using pickle
173
+    # We only write the backup location or, if compressed, the tarball location
168 174
     if not os.path.exists(vc_file):
169 175
         fw = open(vc_file, 'wb')
170 176
         if not use_compression:
@@ -173,10 +179,10 @@ def main():
173 179
             data = [backbase+"/"+time+".tar.gz"]
174 180
         pickle.dump(data, fw)
175 181
         fw.close()
176
-    # if it does exist
182
+
183
+    # If backtrack.txt already exists we use pickle to set its contents to the data var which we will add to
177 184
     else:
178 185
         data = pickle.load(open(vc_file, "rb"))
179
-        #backup_number = (len(data)/3)+1
180 186
         if not use_compression:
181 187
             data += [backup_location]
182 188
         else:
@@ -185,6 +191,7 @@ def main():
185 191
         pickle.dump(data, fw)
186 192
         fw.close()
187 193
 
194
+# Use the except KeyboardInterrupt on main trick to allow the user to C-c anytime
188 195
 if __name__ == "__main__":
189 196
     try:
190 197
         main()

Loading…
Cancel
Save