How to delete old entries of calendar

Hi,

I use Nextcloud since five years ago, and i was wandering if there is a way to delete old appointement in calendar ?
I have one calendar for each family member, but with this many years ago it made a fat files when i export it.

Is there a way to simply delete old event more than 1 month for example ?

Thanks for you help :slight_smile:

Guillermo

Hi folks,
as I could not find a solution, i tried it myself.
If you know, how to connect to your nextcloud database, you can run this sql statement to find out how many calendar entries you have

select count(*) from oc_calendarobjects;
I have 3000 entries, which is peanuts for any database and deleting some won’t change anything.
If you have a lot more you can find the old one by looking at field “lastoccurence”.
This “mysql”-statement counts entries, that have the “last occurence” before year 2020, but other databases might have different timestamp conversion functions:

select count(*) from oc_calendarobjects where year(from_unixtime(lastoccurence)) < 2020;

If you feel confident, you might skip creating a fresh database backup and just run:

delete from from oc_calendarobjects where year(from_unixtime(lastoccurence)) < 2020;

Good luck,
SoulsurferIng

Not good advice.

NEVER edit the Nextcloud database directly.

As long as you do not understand the program code, your Nextcloud may no longer work.

I‘ve the same problem.

My solution: connect the calendar in Thunderbird. Now you can select the entries in the list above the calendar and delete old entries. This is a clean and quick solution :smiling_face:

1 Like

Sorry,
but I still stick with my solution as there are no foreign keys in the databases and I tested this successfully.
Some people might be desperate enough after 2 years to try it themselfs - despite my sacrasim - and they still need to be expirenced to execute SQL via console on the server.

Maybe I cleanup the oc_calendarobjects_props table too, but the most data is table oc_calendarobjects.

@rakekniven is correct. If you delete rows from oc_calendarobjects you will break the synchronization to certain caldav clients like Thunderbird. Every change of the calendar needs a new sync token. Only clients that read the full calendar again will pick up the deletions.

There is no simple way to clean up old data with SQL. Use a dav client and send a REPORT for a time range, then DELETE requests for the specific URIs.

2 Likes