Owncloud 日历 ICS 备份
Owncloud Calendar ICS Backup
我想定期将我的 Owncloud 日历备份为 ICS 文件,以防服务器 运行 出现我没有时间立即修复的问题。为此我写了一个小脚本,可以运行作为cronjob。
欢迎任何反馈、改进和更改!
免责声明:我为我自己和其他 1-2 个朋友 运行 的一个小 Owncloud 实例创建了这个脚本 - 可以这么说,它并不意味着任何 "serious business"。我使用 this and this 站点的脚本作为起点 - 谢谢!
为了创建所有用户日历的 ics 备份,我创建了一个名为 "calendarBackup" 的 Owncloud 用户,其他用户可以与该用户共享他们的日历。我写了一个小脚本,循环遍历所有这些日历并下载 ics 文件。然后将它们放入 calendarBackup 拥有的共享文件夹中,并将备份分发给用户。 (可以进行简单的调整,以便每个用户都有自己的日历文件。)
这种方法的优点是脚本不需要知道所有用户密码。
这里是代码:
#!/bin/bash
#owncloud login data for calendar backup user
OCuser=owncloudUserName
OCpassword="owncloudUserPassword"
OCpath="/var/www/owncloud/"
OCbaseURL="https://localhost/owncloud/"
OCdatabase="owncloudDatabaseName"
#destination folder for calendar backups
dest="/var/www/owncloud/data/owncloudUserName/files/Backup/"
#mysql user data with access to owncloud database
MSQLuser=owncloudMysqlUser
MSQLpassword="owncloudMysqlUserPassword"
#timestamp used as backup name
timeStamp=$(date +%Y%m%d%H%M%S)
archivePassword="passwordForArchivedCalendars"
#apachee user and group
apacheUser="apacheUser"
apacheGroup="apacheGroup"
#create folder for new backup files
mkdir "$dest$timeStamp"
#create array of calendar names from Owncloud database query
calendars=($(mysql -B -N -u $MSQLuser -p$MSQLpassword -e "SELECT uri FROM $OCdatabase.oc_calendars"))
calendarCount=${#calendars[@]}
#create array of calendar owners from Owncloud database query
owners=($(mysql -B -N -u $MSQLuser -p$MSQLpassword -e "SELECT principaluri FROM $OCdatabase.oc_calendars"))
loopCount=0
#loop through all calendars
while [ $loopCount -lt $calendarCount ]
do
#see if owner starts with "principals/users/"
#(this part of the script assumes that principaluri for normal users looks like this: principal/users/USERNAME )
if [ "${owners[$loopCount]:0:17}" = "principals/users/" ]
then
#concatenate download url
url=$OCbaseURL"remote.php/dav/calendars/$OCuser/${calendars[$loopCount]}_shared_by_${owners[$loopCount]:17}?export"
#echo $url
#download the ics files (if download fails, delete file)
wget \
--output-document="$dest$timeStamp/${owners[$loopCount]:17}${calendars[$loopCount]}.ics" \
--no-check-certificate --auth-no-challenge \
--http-user=$OCuser --http-password="$OCpassword" \
"$url" || rm "$dest$timeStamp/${owners[$loopCount]:17}${calendars[$loopCount]}.ics"
#echo ${owners[$loopCount]:17}
fi
#echo "${calendars[$loopCount]} ${owners[$loopCount]}"
loopCount=$(($loopCount + 1))
done
#zip backed up ics files and remove the folder (this could easily be left out, change the chown command though)
zip -r -m -j -P $archivePassword "$dest$timeStamp" "$dest$timeStamp"
rm -R $dest$timeStamp
#chown needed so owncloud can access backup file
chown $apacheUser:$apacheGroup "$dest$timeStamp.zip"
#update owncloud database of calendar backup user
sudo -u $apacheUser php "$OCpath"occ files:scan $OCuser
关于脚本的几点说明:
- 它是为 Debian shell 编写的。
- 它适用于 Mysql 的 Owncloud 9.1。
假设共享日历的下载 URL 如下所示:
OwncloudURL/remote.php/dav/calendars/LoggedInOwncloudUser/CalendarName_shared_by_CalendarOwner?导出
要检查 URL 是否正确,只需在 Web 界面中下载共享日历并检查下载 URL。
假定日历名称存储在 table "oc_calendars" 的 "uri" 列中。
假设日历所有者存储在table"oc_calendars"的"principaluri"列中,并且所有普通用户都以[=58=为前缀].
更新Owncloud文件结构需要sudo权限
- 需要安装zip。
我使用这个脚本已经有一段时间了。从我的 onwCloud 安装中备份日历和联系人非常有帮助。谢谢!
然而,envyrus 的脚本确实让我感到困扰:新 calendars/addressbooks 需要手动与“备份用户”共享,其日历将被备份。这使得脚本对我来说基本上毫无用处,因为我妻子经常创建和删除她的日历和任务列表。
有一个脚本可以自动处理额外的 created/deleted 日历,因为它从数据库中获取所有数据,而不是通过 http 请求(就像来自 envyrus 的脚本)。它只是为数据库中存在的每个 calendar/addressbook 创建一个备份。使用此脚本时不需要提供 username/password 组合。此外,无需与特定用户共享要备份的日历。最后但同样重要的是,该脚本不需要 root 权限。
来自脚本的自述文件:
This Bash script exports calendars and addressbooks from
ownCloud/Nextcloud to .ics and .vcf files and saves them to a
compressed file. Additional options are available.
Starting with version 0.8.0, there is no need anymore for a file with
user credentials because all data is fetched directly from the
database. If only calendars/addressbooks of certain users shall be
backed up, list them in users.txt without any passwords.
也许这对其他人也有帮助:calcardbackup
我想定期将我的 Owncloud 日历备份为 ICS 文件,以防服务器 运行 出现我没有时间立即修复的问题。为此我写了一个小脚本,可以运行作为cronjob。
欢迎任何反馈、改进和更改!
免责声明:我为我自己和其他 1-2 个朋友 运行 的一个小 Owncloud 实例创建了这个脚本 - 可以这么说,它并不意味着任何 "serious business"。我使用 this and this 站点的脚本作为起点 - 谢谢!
为了创建所有用户日历的 ics 备份,我创建了一个名为 "calendarBackup" 的 Owncloud 用户,其他用户可以与该用户共享他们的日历。我写了一个小脚本,循环遍历所有这些日历并下载 ics 文件。然后将它们放入 calendarBackup 拥有的共享文件夹中,并将备份分发给用户。 (可以进行简单的调整,以便每个用户都有自己的日历文件。)
这种方法的优点是脚本不需要知道所有用户密码。
这里是代码:
#!/bin/bash
#owncloud login data for calendar backup user
OCuser=owncloudUserName
OCpassword="owncloudUserPassword"
OCpath="/var/www/owncloud/"
OCbaseURL="https://localhost/owncloud/"
OCdatabase="owncloudDatabaseName"
#destination folder for calendar backups
dest="/var/www/owncloud/data/owncloudUserName/files/Backup/"
#mysql user data with access to owncloud database
MSQLuser=owncloudMysqlUser
MSQLpassword="owncloudMysqlUserPassword"
#timestamp used as backup name
timeStamp=$(date +%Y%m%d%H%M%S)
archivePassword="passwordForArchivedCalendars"
#apachee user and group
apacheUser="apacheUser"
apacheGroup="apacheGroup"
#create folder for new backup files
mkdir "$dest$timeStamp"
#create array of calendar names from Owncloud database query
calendars=($(mysql -B -N -u $MSQLuser -p$MSQLpassword -e "SELECT uri FROM $OCdatabase.oc_calendars"))
calendarCount=${#calendars[@]}
#create array of calendar owners from Owncloud database query
owners=($(mysql -B -N -u $MSQLuser -p$MSQLpassword -e "SELECT principaluri FROM $OCdatabase.oc_calendars"))
loopCount=0
#loop through all calendars
while [ $loopCount -lt $calendarCount ]
do
#see if owner starts with "principals/users/"
#(this part of the script assumes that principaluri for normal users looks like this: principal/users/USERNAME )
if [ "${owners[$loopCount]:0:17}" = "principals/users/" ]
then
#concatenate download url
url=$OCbaseURL"remote.php/dav/calendars/$OCuser/${calendars[$loopCount]}_shared_by_${owners[$loopCount]:17}?export"
#echo $url
#download the ics files (if download fails, delete file)
wget \
--output-document="$dest$timeStamp/${owners[$loopCount]:17}${calendars[$loopCount]}.ics" \
--no-check-certificate --auth-no-challenge \
--http-user=$OCuser --http-password="$OCpassword" \
"$url" || rm "$dest$timeStamp/${owners[$loopCount]:17}${calendars[$loopCount]}.ics"
#echo ${owners[$loopCount]:17}
fi
#echo "${calendars[$loopCount]} ${owners[$loopCount]}"
loopCount=$(($loopCount + 1))
done
#zip backed up ics files and remove the folder (this could easily be left out, change the chown command though)
zip -r -m -j -P $archivePassword "$dest$timeStamp" "$dest$timeStamp"
rm -R $dest$timeStamp
#chown needed so owncloud can access backup file
chown $apacheUser:$apacheGroup "$dest$timeStamp.zip"
#update owncloud database of calendar backup user
sudo -u $apacheUser php "$OCpath"occ files:scan $OCuser
关于脚本的几点说明:
- 它是为 Debian shell 编写的。
- 它适用于 Mysql 的 Owncloud 9.1。
假设共享日历的下载 URL 如下所示:
OwncloudURL/remote.php/dav/calendars/LoggedInOwncloudUser/CalendarName_shared_by_CalendarOwner?导出
要检查 URL 是否正确,只需在 Web 界面中下载共享日历并检查下载 URL。
假定日历名称存储在 table "oc_calendars" 的 "uri" 列中。
假设日历所有者存储在table"oc_calendars"的"principaluri"列中,并且所有普通用户都以[=58=为前缀].
更新Owncloud文件结构需要sudo权限
- 需要安装zip。
我使用这个脚本已经有一段时间了。从我的 onwCloud 安装中备份日历和联系人非常有帮助。谢谢!
然而,envyrus 的脚本确实让我感到困扰:新 calendars/addressbooks 需要手动与“备份用户”共享,其日历将被备份。这使得脚本对我来说基本上毫无用处,因为我妻子经常创建和删除她的日历和任务列表。
有一个脚本可以自动处理额外的 created/deleted 日历,因为它从数据库中获取所有数据,而不是通过 http 请求(就像来自 envyrus 的脚本)。它只是为数据库中存在的每个 calendar/addressbook 创建一个备份。使用此脚本时不需要提供 username/password 组合。此外,无需与特定用户共享要备份的日历。最后但同样重要的是,该脚本不需要 root 权限。
来自脚本的自述文件:
This Bash script exports calendars and addressbooks from ownCloud/Nextcloud to .ics and .vcf files and saves them to a compressed file. Additional options are available.
Starting with version 0.8.0, there is no need anymore for a file with user credentials because all data is fetched directly from the database. If only calendars/addressbooks of certain users shall be backed up, list them in users.txt without any passwords.
也许这对其他人也有帮助:calcardbackup