Created
January 3, 2019 18:55
-
-
Save tfl/c1f5cd800069b4fb95ea92a0b69d6bf0 to your computer and use it in GitHub Desktop.
Ruby script to transfer Davical ics and vcf data from database to database. Maybe usefull if standard migration procedures fail
This file contains hidden or 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
########################################################################## | |
# If all davical updates failed: create a new instance on your new system | |
# and transfer your data with this script and curl from your old server | |
# to your new server. The example below does this with your calendar data. | |
# Change URL, caldav_type and file extension and you can transfer your | |
# vcards as well. I did this a few days ago and it worked very well. | |
########################################################################## | |
require 'pg' | |
begin | |
conn = PG.connect :dbname => 'davical', :user => 'davical_app' | |
# for vcards use VCARD as caldav_type | |
# replace <ID> with a valid user id | |
result = conn.exec("select caldav_data from caldav_data where user_no = <ID> and caldav_type = 'VEVENT'") | |
result.each do |row| | |
data = row['caldav_data'] | |
id = data.scan(/UID:(.+)/).first.last.strip | |
# for Events use .ics as file extension, use .vcf for vcards | |
# Files will be saved to 'dump' subdir - create it! or remove 'dump/' | |
open("dump/#{id}.ics", 'w') do |d| | |
d.puts data | |
end | |
# again: change file extension as needed | |
# set user and password as needed | |
# the default calendar url ends in /caldav.php/USER/calendar/ | |
# the default vcard url ends in /caldav.php/USER/addresses/ | |
`curl -u user:pass --upload-file dump/#{id}.ics URL` | |
end | |
rescue PG::Error => err | |
puts "DB error: #{err.message}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment