Quick Update to PostgreSQL backup scripts for OS X Server 3.1.1

Just a quick and dirty script update to backup individual service Postgres databases in the latest OS X Server. The sockets have moved again. These locations feel a bit more stable.

#!/bin/bash
backupdir='/Library/Server/Backups/PostgreSQL/';
server_root='/Applications/Server.app/Contents/ServerRoot';

day=`date +%u`;
mkdir -p $backupdir/$day;

echo "PostgreSQL Backup for $HOSTNAME";
echo "================================="
echo `date`;
$server_root/usr/bin/pg_dump -U _devicemgr -h /Library/Server/ProfileManager/Config/var/PostgreSQL/ -c devicemgr_v2m0 | gzip -c > "$backupdir/$day/devicemgr_v2m0.sql.gz";
$server_root/usr/bin/pg_dump -U _teamsserver -h /Library/Server/Wiki/PostgresSocket/ -c collab | gzip -c > "$backupdir/$day/collab.sql.gz";
$server_root/usr/bin/pg_dump -U caldav -h /var/run/caldavd/PostgresSocket/ -c caldav | gzip -c > "$backupdir/$day/caldav.sql.gz";
chmod 600 "$backupdir/$day/devicemgr_v2m0.sql.gz";
chmod 600 "$backupdir/$day/collab.sql.gz";
chmod 600 "$backupdir/$day/caldav.sql.gz";
#for database in `$server_root/usr/bin/psql -U _postgres -h "$psql_socket" -lt | awk '{print $1}' | grep -vE '\||^$|template|postgres'`;
#   do
#   printf "Exporting $database...";
#   $server_root/usr/bin/pg_dump -U _postgres -h "$psql_socket" -c $database | gzip -c > $backupdir/$day/$database.sql.gz;
#   /bin/chmod 600 $backupdir/$day/$database.sql.gz;    
#   printf "done\n";
#done
echo `date`;
echo;
exit 0;

I’m sure there’s some smarter stuff I could be doing in here. Let me know if you see anything.

Wednesday, May 7, 2014   ()

Apple Australia Quietly Extends Warranties to 24 Months [MacTalk.com.au]

Mission accomplished.

Updated PostgreSQL backup scripts for 10.8.2 / OS X Server 2.2

IMPORTANT (2013-11-19): All of this has changed in Mavericks / OS X Server 3.x. Each service has its own instance of Postgres. See some of the comments below for the new socket locations.

In Mountain Lion 10.8.2 along with OS X Server 2.2, Apple started employing two separate instances of Postgres, one for the built-in services, and the other for use by custom applications (e.g. Roundcube). My old backup script doesn’t properly understand the differences, or the new socket, so I have had to rewrite it. I also quickly banged up a second version that backs up the user databases too.

First, the system databases:

#!/bin/bash
backupdir='/Library/Server/Backups/PostgreSQL/';
server_root='/Applications/Server.app/Contents/ServerRoot';
psql_socket='/Library/Server/PostgreSQL For Server Services/Socket/';

day=`date +%u`;
mkdir -p $backupdir/$day;

echo "PostgreSQL Backup for $HOSTNAME";
echo "================================="
echo `date`;
for database in `$server_root/usr/bin/psql -U _postgres -h "$psql_socket" -lt | awk '{print $1}' | grep -vE '\||^$|template|postgres'`;
    do
    printf "Exporting $database...";
    $server_root/usr/bin/pg_dump -U _postgres -h "$psql_socket" -c $database | gzip -c > $backupdir/$day/$database.sql.gz;
    /bin/chmod 600 $backupdir/$day/$database.sql.gz;    
    printf "done\n";
done
echo `date`;
echo;
exit 0;

Obviously, update the backupdir to the directory of your choice.

Next, the script to backup any databases you’ve added:

#!/bin/bash
backupdir='/Library/Server/Backups/PostgreSQL/';
server_root='/Applications/Server.app/Contents/ServerRoot';

day=`date +%u`;
mkdir -p $backupdir/$day;

echo "PostgreSQL Backup for $HOSTNAME";
echo "================================="
echo `date`;
for database in `$server_root/usr/bin/psql -U _postgres -lt | awk '{print $1}' | grep -vE '\||^$|template|postgres'`;
    do
    printf "Exporting $database...";
    $server_root/usr/bin/pg_dump -U _postgres -c $database | gzip -c > $backupdir/$day/$database.sql.gz;
    /bin/chmod 600 $backupdir/$day/$database.sql.gz;    
    printf "done\n";
done
echo `date`;
echo;
exit 0;

The only difference is that the first script uses a custom socket.

Tuesday, March 5, 2013   ()

Anonymous said: Is there any way to backup the OS X 10.8 mail server without time machine? I do not like time machine but i do want a backup. i use software for cloning my drive but i want to be able to just backup mail. I can't find the answer on internet. thanks in advance for your reply!

Mail is just stored as files on the server, so any backup tool that can back up files should be fine. Also, at least with 10.8.2 and OS X Server 2.2 and on, all mail data and configuration are nicely compartmentalized to /Library/Server/Mail, so just back up that directory.

Thursday, February 28, 2013   ()

Belgian consumer group sues Apple over its ‘misleading and illegal’ warranty policy

Action in Australia please.

Open Directory 7-Day Rotating Backup Script

This script just saved my bacon last night as I awoke to a corrupted directory resulting from a power outage. I stood on the shoulders of others to build this, but I unfortunately don’t have record of those sources. Regardless, here is the script. Obviously, set archive_path and archive_password to your liking. Don’t mess with archive_name if you want to maintain the 7-day rotation.

#!/usr/bin/expect -f
set timeout 300
set date [timestamp -format "%u"]
set archive_path "/Library/Server/Backups/OpenDirectory"
set archive_password "PutYourDesiredPasswordHere"
set archive_name "OpenDirectory_Day_"

spawn /usr/sbin/slapconfig -backupdb $archive_path/$archive_name$date
expect "Enter archive password"
send "$archive_password\r"
expect eof
Friday, November 30, 2012   ()

EU Justice Commissioner calls for investigation into Apple’s warranty practices | 9to5Mac

This is exactly what I’d like to see examined in Australia

How to Get Apple to Replace a Defective Out-of-Warranty iPhone in Australia

With the two year anniversary of the release of the iPhone 4 in Australia just past, many folks who bought their iPhone 4 after that period would now be approaching the end of their contracts. The iPhone 4 has been known to experience some common defects later in its life (does anyone have a flaky home button?), so here is a guide for how to get Apple to honor the Trade Practices Act of 1974, and provide you with free warranty service, i.e. a replacement for your defective iPhone.

Wednesday, August 29, 2012 — 1 note   ()

A Better AppleScript for Enabling and Disabling Flash in Safari

I recently wrote two separate scripts, one to enable, and the other to disable Flash in Safari. However, sometimes I couldn’t tell whether Flash was already enabled or disabled and choosing the wrong menu option gave a cryptic shell error.

So I decided to rewrite it as one script, Toggle Flash Player, which firstly identifies the state of the plugin, and then lets you choose whether or not you want to accordingly enable or disable it.

Additionally, the script now tests for the presence of the disabled plug-in folder, and offers to create it for you if it’s not there.

Friday, August 24, 2012 — 1 note   ()

Integrating Dropbox with Mountain Lion’s iCloud-enabled iWork

I have a workflow where I maintain a few Numbers spreadsheets that I need a business partner to be able to regularly review. Before Mountain Lion, I just put a symbolic link to ~/Documents/Spreadsheets folder inside ~/Dropbox, shared that Dropbox folder with him, and used the Mac version of Numbers to manage the files.

Now that Mountain Lion has arrived, and there is proper integration between the iOS and Mac versions of iWork, I want to be able to work on these documents on my iOS devices as well, so I’ve moved the relevant spreadsheets from ~/Documents/Spreadsheets to iCloud. Unfortunately, this breaks the symbolic link in Dropbox.

Wednesday, August 8, 2012   ()