I am trying to format output from the following Python 3.x script. Here is the function that I'm calling:
def daily_backup():
# Header for /var/log/me/rsync_backup.log
print(" ")
print("#" * 75)
print(get_dt())
print("#" * 75)
print(" ")
# Update timestamp on backup file, notify user that backup has started
Path("/var/log/me/rsync_backup_ran").touch()
notify_send("Daily backup started","%s" % get_dt(),"info")
# Every week, start over with current files
if today_name != "Sunday":
rsync_command = "rsync -avbH --stats --exclude-from=/home/me/bin/rsync_backup.ecl"
else:
rsync_command = "rsync -avH --stats --exclude-from=/home/me/bin/rsync_backup.ecl " \
"--delete --delete-excluded"
# System configs, crontabs, installed software lists
INSTALLED = "/home/me/.config/installed"
if not os.path.isdir(INSTALLED):
os.mkdir(INSTALLED)
os.system("dpkg --get-selections > %s/installed-software" % INSTALLED)
os.system("ls /home/me/.local/share/flatpak/app > %s/installed-flatpaks" % INSTALLED)
os.system("rsync -avb /etc/apt/sources.list.d %s" % INSTALLED)
os.system("rsync -avb /var/spool/cron %s" % INSTALLED)
os.system("rsync -avb /etc/libvirt/qemu %s" % INSTALLED)
# My data
for i in range(3):
cmd_format = "%s %s %s/%s/daily"
cmd_info = (rsync_command, backup_paths[i], backup_root, backup_folders[i])
os.system(cmd_format % cmd_info)
notify_send("Daily backup ended","%s" % get_dt(),"info")
daily_backup()
The script works, except for that the header I create (at the top of the function) doesn't get printed until after all of the os.system calls. Is this normal behavior? How can I correct this?