xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #2967: extract-trac-attachments.sh

File extract-trac-attachments.sh, 1.4 KB (added by Antoine Martin, 8 months ago)

needed to keep links to the attachments working

Line 
1#!/bin/sh
2#
3# This is a helper shell script to extract all attachment files from a
4# working trac installation and store it into a dedicated directory which
5# can then be put onto some webspace and the --attachment-url option being using
6# with trac-hub to reference these files in attachment comments to tickets
7#
8# Copyright 2016 (c) Jens Maus <mail@jens-maus.de>
9#
10# This script connects to an `sqlite` database and directly exports the files
11# using `trac-admin`. If you don't have access to `trac-admin` or use a MySQL
12# database, take a look at the `download-trac-attachments-mysql.sh` script.
13
14TRAC_ENV=/var/www/www.yam.ch/trac
15TRAC_DB=${TRAC_ENV}/db/trac.db
16OUTPUT_DIR=/tmp/trac
17
18if [ "$USER" != "root" ]; then
19 echo "ERROR: script has to be run as super-user (sudo)"
20 exit 2
21fi
22
23# get all ids and filename of all attachments
24output=$(sqlite3 ${TRAC_DB} "select id,filename from attachment where type='ticket';")
25
26# make sure the output dir is clean
27rm -rf ${OUTPUT_DIR}
28
29# walk through the output
30IFS=$'\n'
31for line in ${output}; do
32  ticket=$(echo $line | cut -d '|' -f 1)
33  file=$(echo $line | cut -d '|' -f 2)
34
35  mkdir -p ${OUTPUT_DIR}/${ticket}
36  echo -n "Saving attachments of ticket #${ticket}... "
37  trac-admin ${TRAC_ENV} attachment export ticket:${ticket} "${file}" ${OUTPUT_DIR}/${ticket} 2>/dev/null
38  if [ $? -ne 0 ]; then
39    echo "ERROR!"
40  fi
41  echo "done."
42done