Backup ZNC Logs automatically

This is a short script to automatically backup the ZNC logs from multiple remote servers to a local directory.

If you want to run it on a system which isn't Mac OS you'll probably have to tweak a few things. Especially the lines containing terminal-notifier because they make use of the Mac OS notification center. Just replace them with echo statements or a similar notification framework for your operating system.

The script


To get the notifications to the notification center install you'll have to install terminal-notifier. You can grab it from Github or install it via Homebrew.

Get the script

Download the script and make it executable.

git clone backup-znc-logs
chmod +x backup-znc-logs/

Open the script and edit the line which defines the SCRIPT_HOME. That's the directory where you'll create subdirectories for the various servers. In our case we'll create a directory called "" and "" because these are the two servers we want to back up.

cd ~/Documents/Textual\ Logs/ZNC/

Create config files

Now it's time to create a config file to tell the script where it should grab the files from and where to store them. We do this by creating an invisible file called .config-backup in the server directory.

vim ~/Documents/Textual\ Logs/ZNC/

Add these lines and costomize them to your needs. (You don't have to copy the comments) Make sure not to excape the spaces in the path names because rsync doesn't like this.

# The name of the server which is used in notifications.

# The name of the file where we store the timestamp of the last backup. Just in case you feel like changing it. You probably won't have to change this.

# The path and username of the remote server where the logs are stored

# The path the logs should be synced to on the machine the script is running from. `${HOME}` is used instead of `~`.
PATH_LOCAL="${HOME}/Documents/Textual Logs/ZNC/"

You have to create a file like this for every server you want to backup. For this to work it's required that you are using ssh keys and not passwords.

Run the script

Note: Per default the script will only create a backup every 24h. If you want to change that search for the value 86400 and change that to something you prefer.

If you run the script and the last backup isn't older than 24h the output you'll see looks like this:

Scripts|⇒ ./ : Last backup < 24h old. Do nothing. : Last backup < 24h old. Do nothing.

If you want to automatically run the script you could use something like this: