Wednesday, April 1, 2020

Manually Scheduling your Mac Backups
(for macOS Sierra and later)

This will enable you to have flexibility to schedule and run your backups for your mac.


1.      Disable the automatic backups you have in your time machine preference window by unticking the Back Up Automatically checkbox.





2.     We need to configure Time Jobs using launchd, it’s the cron of MacOS for those that are familiar with Unix.  For more information on how to configure such jobs, see the man pages of launchd.plist.

To add a new backup job using launchd:

a.      Open a terminal session and switch to root user

sudo -i

<use your user admin password here that you used to login to your mac session)

b.      Go to /Library/LaunchDaemons and open a vi session and create your backup plist file with the contents below.

The below job will run every Sunday at 23:33 local time. You can adjust the date and time as per your preference.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
   <dict>
<key>Label</key>
<string>com.myimac.backup</string>
<key>ProgramArguments</key>
<array>
               <string>/usr/bin/tmutil</string>
               <string>startbackup</string>
               <string>--auto</string>
               <string>--block</string>
</array>
<key>StandardErrorPath</key>
<string>/var/root/timemachinebackup_err.log</string>
<key>StandardOutPath</key>
<string>/var/root/timemachine.log</string>
<key>StartCalendarInterval</key>
<dict>
               <key>Hour</key>
               <integer>23</integer>
               <key>Minute</key>
               <integer>33</integer>
                <key>Weekday</key>
                <integer>7</integer>
</dict>
   </dict>
</plist>

Save your file to a file ending in plist. It would help if it has the same as the Label string highlighted above.

com.myimac.backup.plist

c.      To schedule the above plist file  or backup job issue the following commands as root:

launchctl load /Library/LaunchDaemons/com.myimac.backup.plist

To check if it has been scheduled:

launchctl list | grep 'myimac'

Output:
-     0            com.giaimac.backup

To start your first backup job execution

launchctl start com.giaimac.backup

To check if its running

launchctl list | grep 'myimac'

Output:
94990        0            com.myimac.backup

       Or Open your Time Machine Preference and you will see there that the backup is running.

To Stop the said job from running in its scheduled time:

launchctl unload /Library/LaunchDaemons/com.myimac.backup.plist

You can further check the following sites for detailed information on  how to use schedule jobs in mac or use the launchctl command