Create a gist now

Instantly share code, notes, and snippets.

@Dineshs91 /README
Last active Oct 16, 2016

What would you like to do?
Backup scripts
## Restoring with tar from a compressed archive.
### Test the command first with 't' argument
tar -ztvpf /archive/full-backup-02-March-2016.tar.gz
### Extract with 'x' argument
tar -zxvpf /archive/full-backup-02-March-2016.tar.gz
#! /bin/bash
# For restoration use,
# tar -zxvpf /archive/backup-xx-Oct-xxxx.tar.gz etc/profile
#
# Only etc/profile is restored. Don't mention anything
# to restore completely.
dev_dir='/Users/dinesh/Documents/developer'
my_dir='/Users/dinesh/Documents/my'
ext_hard_disk_dir="/Volumes/vault/backup/full-backup-`date '+%d-%B-%Y'`.tar.gz"
echo "Backing up data"
echo "$dev_dir $my_dir"
echo "Dest directory $ext_hard_disk_dir"
time tar -cf "$ext_hard_disk_dir" \
--directory / \
--exclude='node_modules' \
--exclude='bower_components' \
--exclude='source_code' \
--exclude='utilities' \
--exclude='.git' --exclude='venv' \
--exclude='backup-and-restore' \
"$dev_dir"
exit_status=$?
echo ""
if [ $exit_status -eq 0 ];then
echo ">>>> Backup completed succesfully <<<<"
else
echo ">>>> Backup failed <<<<"
fi
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>custom.sync</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Path/to/sync.sh</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/dinesh/logs/custom-sync.txt</string>
</dict>
</plist>
#! /bin/bash
# This script syncs directories with google drive.
my_dir='/Users/dinesh/Documents/my'
dest_dir='/Users/dinesh/Google Drive/'
# Directories will be synced when any changes are detected
# to the directories being watched.
/usr/local/bin/fswatch -o "$my_dir" \
| while read
do
rsync -a --delete "$my_dir" "$dest_dir"
done
Owner
Dineshs91 commented Oct 16, 2016 edited

Commands to start with launchctl.

~/.backup-and-restore

Put the custom.sync.plist file in ~/Library/LaunchDaemons

### Load a job

$ launchctl load -w  ~/Library/LaunchDaemons/custom.sync.plist

### Unload a job

$ launchctl unload ~/Library/LaunchDaemons/custom.sync.plist

### List jobs

$ launchctl list
$ launchctl list | grep 'custom.sync'

Start and stop are not required.
### Starting a job

$ launchctl start custom.sync

### Stoping a job

$ launchctl stop custom.sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment