Compare commits

...

14 Commits

2 changed files with 37 additions and 8 deletions

View File

@ -1,4 +1,7 @@
# Mikes Backup
*** Currently Archived; Read Section Below ***
Easily run both *full* and *differential* backups with rsync, to a local folder or an SSH server.
This script is really just a wrapper around rsync's beautiful functionality. It presents a simplified interface for one very narrow use case: Simplifying the process of running daily backups:
@ -6,6 +9,10 @@ This script is really just a wrapper around rsync's beautiful functionality. It
* Otherwise, it will automatically choose a *full* or *differential* backup type, based on whether it detects an existing *full* backup folder at the backup destination
* For *differential* backups, it automatically generates a folder based on today's date and time, making it easier to store many differentials without the need to manually fuss with anything
## Archive Status
I've decided to discontinue development of this project because [restic](https://restic.net/) is so much more robust, useful, and cool. *Mike's Backup* still works as of this writing (2022-07-20), but I've moved all my personal backups over to restic.
## Requirements
* rsync
* python3
@ -17,6 +24,7 @@ This script is really just a wrapper around rsync's beautiful functionality. It
* ```--diff``` Same as ```---differential```
* ```--no-incremental``` Always force differentials to link back to the *full* backup, and not the most recent *differential*
* ```--log-dir <directory>``` Let's you set the log output directory
* ```--log-name``` Let's you set a name to the log file
* ```--source-dir <directory>``` Specifies the local source directory
* ```--include <directory>``` Specifies another local source directory to include in the backup
* ```--source-mountpoint <directory>``` Make sure a local mountpoint is mounted before continuing

View File

@ -15,6 +15,7 @@ class MikesBackup:
#
__log_dir = None
__log_name = None
__remote_host = None
__remote_user = None
@ -55,6 +56,7 @@ class MikesBackup:
s += "MikesBackup Class Instance"
s += "\nLog Dir: " + str(self.__log_dir)
s += "\nLog Name: " + str(self.__log_name)
s += "\nRemote Host: " + str(self.__remote_host)
s += "\nRemote User: " + str(self.__remote_user)
s += "\nDestination Dir Base: " + str(self.__destination_dir_base)
@ -150,6 +152,12 @@ class MikesBackup:
self.__log_dir = sys.argv[a + 1]
self.log("Found log dir: " + self.__log_dir)
a = a + 1
elif arg == "--log-name":
valid_arg = True
self.__log_name = sys.argv[a + 1]
self.log("Found log name: " + self.__log_name)
self.close_log_file()
a = a + 1
elif arg == "--source-dir":
valid_arg = True
if self.__source_dir:
@ -276,7 +284,7 @@ class MikesBackup:
return False
#
self.log("Checking for remote destination path")
self.log("Checking for remote destination path: " + destination_path)
command = [
"[ -d " + destination_path + " ]"
]
@ -368,12 +376,15 @@ class MikesBackup:
self.log("Rsync seems to have finished successfully")
self.log("Because a full backup has succeeded, will now delete any differential backups")
self.execute_remote_ssh_command(
[
"rm",
"-rfv",
self.make_remote_differential_backup_path_base()
])
args_remove_differentials = [
"rm",
"-rfv",
self.make_remote_differential_backup_path_base()
]
if self.is_using_ssh():
self.execute_remote_ssh_command(args_remove_differentials)
else:
self.execute_command(args_remove_differentials)
self.log("Finished deleting old differentials")
#
@ -439,8 +450,14 @@ class MikesBackup:
if not log_dir:
return None
# Filename
file_name = self.get_datetime_for_filename()
if self.__log_name:
file_name += "-" + self.__log_name
file_name += ".log"
# Path
log_path = os.path.join(log_dir, self.get_datetime_for_filename() + ".log")
log_path = os.path.join(log_dir, file_name)
return log_path
@ -641,8 +658,11 @@ class MikesBackup:
"--compress",
"--progress",
"--stats",
"--verbose",
"--human-readable",
"--itemize-changes",
"--no-links",
"--one-file-system",
"--delete",
"--delete-excluded"
]
@ -747,6 +767,7 @@ class MikesBackup:
raise Exception("Unsupported command datatype")
# Spawn
# print(args)
process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# process = subprocess.Popen(args)
stdout, stderr = process.communicate()