Owncloud: script per esportare calendari .ics (per prevenire eventuali perdite di dati)

Per chi usa Owncloud, una delle maggiori problematiche è quella di riuscire a backuppare i calendari in formato .ics, in modo da poterli ripristrinare in caso di crash o importarli in altri calendari che leggono .ics
Questa breve guida mostra come creare uno script php. da dare in pasto a crontab, per effettuare un backup giornaliero della nostra /nostre agende
In pratica dobbiamo prima installare “composer” quindi “sabre/vobject” ed infine creare lo script

———————————————————————–

Tested on
O.S. Ubuntu 14.04
O.Cloud server ver. 8.1.8

needs:
-composer
-sabre

composer
command line to install composer
php composer-setup.php –install-dir=bin –filename=composer
Now just run php bin/composer in order to run Composer.

to test composer if it is installed:
command line composer

forum2.JPG
forum2.JPG (57.32 KiB) Visto 93 volte

sabre/vobject
command line to install sabre using composer
composer require sabre/vobject ~4.1

If all went well you should see the following folder

forum3.jpg
forum3.jpg (63.24 KiB) Visto 93 volte

into vendor directory you have to see:

forum 4.JPG
forum 4.JPG (16.05 KiB) Visto 93 volte

now you must create this script (source from https://statuscode.ch/2015/06/Combining … ilability/)
and put it on your server to test before putting it in a cron job to automate

<?php
// Use “composer require sabre/vobject” to get the required libraries
require_once(‘./vendor/autoload.php’);

use Sabre\VObject;

// Configure your data
$remoteHost = ‘http://xxx.xxx.xxx.xxx/owncloud’;
$calendarName = ‘yourcalendarname’;
$username = ‘usercalendarname’;
$password = ‘pswusercalendar’;

// Get ownCloud calendar
$curl = curl_init($remoteHost . ‘/remote.php/caldav/calendars/’.$username.’/’.$calendarName.’?export’);
curl_setopt($curl, CURLOPT_USERPWD, $username . “:” . $password);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$ics = curl_exec($curl);
curl_close($curl);

// Parse calendar file
$calendar = VObject\Reader::read($ics);

// Replace all SUMMARY fields with a value of “Reserved”
// foreach($calendar->children() as $children) {
// if($children instanceof VObject\Component\VEvent) {
// $children->SUMMARY = ‘Reserved’;
}
}

// Put the resulting ICS to “destinationdirectory”/public.ics
file_put_contents(‘Scrivania/TEST/public.ics’, $calendar->serialize());
?>

to test you can write in command line:
php scriptaddress scriptname.php

if runs well you can see something like this

forum1.jpg
forum1.jpg (204.67 KiB) Visto 93 volte

attention: if you return an error like this:
PHP Warning: require_once(./vendor/autoload.php): failed to open stream:
verify you not are writing in command line as “sudo”

tratto dal mio forum

Comments

Lascia un commento