Skip to content

Instantly share code, notes, and snippets.

@tribut
Created October 20, 2015 08:25
Show Gist options
  • Save tribut/c98eb5ab82563058cd5a to your computer and use it in GitHub Desktop.
Save tribut/c98eb5ab82563058cd5a to your computer and use it in GitHub Desktop.
Backup ownCloud calendar and contacts to a git repository
#!/bin/sh
MYNAME="$(readlink -f "$0")"
BASEDIR="$(dirname "$MYNAME")"
AUTHFILE="$HOME/private/owncloud"
CURL="curl --netrc-file $AUTHFILE --fail --silent --show-error"
CONTACTSPATH="$BASEDIR/contacts"
CALENDARSPATH="$BASEDIR/calendars"
BASEURL="https://owncloud.server.example/remote.php"
USER="user1"
CONTACTS="work private other"
CALENDARS="defaultcalendar work other"
cd "$BASEDIR" &&
mkdir -p "$CONTACTSPATH" &&
mkdir -p "$CALENDARSPATH" || exit 1
for contact in $CONTACTS; do
$CURL -o "$CONTACTSPATH/${contact}.vcf" "$BASEURL/carddav/addressbooks/$USER/$contact?export"
done
for calendar in $CALENDARS; do
$CURL -o "$CALENDARSPATH/${calendar}.ics" "$BASEURL/caldav/calendars/$USER/$calendar?export"
done
git add "$CONTACTSPATH" "$CALENDARSPATH"
git commit -q -m 'Update' >/dev/null # why is --quiet not quiet?
git status --short # just in case commit fails silently
# now that we have redirected the output
git push -q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment