Created
October 20, 2015 08:25
-
-
Save tribut/c98eb5ab82563058cd5a to your computer and use it in GitHub Desktop.
Backup ownCloud calendar and contacts to a git repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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