Tiny Tiny RSS: Community

Upgrading to use Git

I realize that I should have updated to using Git before now, I’m currently running 1.15.3. But since I am just now doing so, I wanted to make sure that I should run Git (as described on the Installation Guide) first. After that is where I am looking for advice. Obviously, I have an existing database and don’t want to start from scratch. When I got to http://yourdomain/tt-rss/install/ is there a way to point it at the existing database? Or should I just edit the config files directly?

Don’t go to the /install. Move your original tt-rss directory to something like tt-rss-old. Then do a git clone to get the git version. Then cp -p tt-rss-old/config.php tt-rss/

When you visit your site then it should just work (or tell you to update schema, permissions, etc.).


I made my own script to maintain TT-RSS updated and with option to get back to previous version:
I’m using ln to version:

[[email protected]]$ ls -l
total 28
drwxr-xr-x. 22 claudio www-data 4096 may  5  2016 15.7.7af2e795
drwxr-xr-x  22 claudio www-data 4096 sep 10  2016 16.1.638fdf73
drwxr-xr-x  22 claudio www-data 4096 feb 20  2017 16.3.cde82722
drwxr-xr-x  23 claudio www-data 4096 jul  1 13:07 17.1.07d3431e
drwxr-xr-x  22 claudio www-data 4096 abr 30 21:12 17.1.b835a528
drwxr-xr-x  23 claudio www-data 4096 sep 19 11:11 17.4.07d3431e
drwxr-xr-x  23 claudio www-data 4096 sep 19 16:10 17.4.af13f300
lrwxrwxrwx   1 root    root       13 sep 19 15:51 html -> 17.4.af13f300

My script:


TAGLOCAL=`git rev-parse HEAD`
git pull
TAGREMOTE=`git rev-parse HEAD`

if [ $VERLOCAL != $VERREMOTO ] ; then
    echo Changes detected...
    VERLOCAL=`grep "define('VERSION_STATIC" $DIRWEB/html/include/version.php | cut -d"'" -f4`.`echo $TAGLOCAL | cut -c1-8`
    VERREMOTE=`grep "define('VERSION_STATIC" $DIRWEB/html/include/version.php | cut -d"'" -f4`.`echo $TAGREMOTE | cut -c1-8`
    echo VersionLocal=$VERLOCAL
    echo VersionRemote=$VERREMOTE

    cd $DIRWEB
    echo $DIRWEB
    echo Prev: >> $TMPLOG
    ls -l >> $TMPLOG
    ls -l
    echo Copying new files
    mv $DIRWEB/html/config.php $DIRWEB/html/config.php.$VERLOCAL
    rsync -rvch --exclude=.git/ --exclude=.buildpath --exclude=.gitignore --exclude=.htaccess --exclude=.project $DIRGIT/ $DIRWEB/$VERREMOTE >> $TMPLOG
    mkdir -p $DIRWEB/$VERREMOTE/.git/refs/heads
    echo Version change
    rm $DIRWEB/html
    ln -s $VERREMOTO $DIRWEB/html
    cp $DIRGIT/.git/refs/heads/master $DIRWEB/html/.git/refs/heads/master
    ls -l

    echo Reconfigure
    mv $DIRWEB/html/config.php-dist $DIRWEB/html/config.php
    mkdir -p $DIRWEB/html/cache/images
    mkdir -p $DIRWEB/html/cache/upload
    mkdir -p $DIRWEB/html/cache/export
    mkdir -p $DIRWEB/html/cache/js
    # this preserve my configs and left new parameters untouched
    sed -i "/DB_TYPE/ s/pgsql/mysql/" $DIRWEB/html/config.php
    sed -i "/DB_USER/ s/fox/myuser/" $DIRWEB/html/config.php
    sed -i "/DB_NAME/ s/fox/mydatabase/" $DIRWEB/html/config.php
    sed -i "/DB_PASS/ s/XXXXXX/mypassword/" $DIRWEB/html/config.php
    sed -i "/DB_PORT/ s/''/'3396'/" $DIRWEB/html/config.php
    sed -i "/SELF_URL_PATH/ s/example.org\/tt-rss/myreader.mydomain.com/" $DIRWEB/html/config.php
    # replace with Crypt Key previously recorded
    sed -i "/FEED_CRYPT_KEY/ s/''/'MyCrYpTkEy'/" $DIRWEB/html/config.php
    sed -i "/SIMPLE_UPDATE_MODE/ s/false/true/" $DIRWEB/html/config.php
    sed -i "/PLUGINS/ s/, note//" $DIRWEB/html/config.php
    echo Apply right permissions
    # user www-data or apache or whatever
    sudo chown -R claudio:www-data $DIRWEB/html/
    sudo chmod 664 $DIRWEB/html/config.php
    sudo chmod -R 777 $DIRWEB/html/cache
    sudo chmod -R 777 $DIRWEB/html/feed-icons
    sudo chmod -R 777 $DIRWEB/html/lock
    echo Post: >> $TMPLOG
    ls -l >> $TMPLOG
    ls -l
    echo Log in $TMPLOG
    echo NO changes

@cktt, that is a complicated script indeed!

Thanks, I appreciate it. Just had a couple of things to modify, but I’m up and running.

It is. Somewhat unnecessarily, too. Git already tracks changes so one can just roll back by checking out a previous commit point. Creating a new directory/clone each time doesn’t make sense; the manually modifying the config file adds complexity as well.

Nevertheless, I can understand and appreciate that some people have their workflows and live by them.

e: What I do is keep the git repo cloned and run from that. In .git/hooks I’ve created a post-merge script that runs automatically after a git pull and updates permissions, etc. Separately, I have a cron job that just runs a git remote update on this clone and compares the hashes on the master branch and sends me an email with the commit log so I know there are changes. If the changes are important (security, bug fixes that affect me, etc.) I can login and run git merge (since the updates are already fetched), or git pull (if more updates have come in since the email). If the changes don’t affect me (like the recent plugin updates), I can ignore them for a few days.

@JustAMacUser You can subscribe to an RSS feed of the changes to tt-rss in git… I am using tt-rss to read it⸮ :slight_smile:

Here is my update script:

# Backup DB.                                                                    
DB="${HOME}/backups/"`date +'ttrss-pg-backup-%Y%m%d.sql'`                       
pg_dump ttrss > ${DB}                                                           
xz ${DB}                                                                        
# Backup TTRSS                                                                  
BAK="${HOME}/backups/"`date +'ttrss-src-backup-%Y%m%d.tar'`                     
tar -cf ${BAK} ${TTRSS}                                                         
xz ${BAK}                                                                       
## Update via git up:                                                           
# git config --global alias.up '!git remote update -p; git merge --ff-only @{u}'
cd ${TTRSS}                                                                     
git up

I do not really need to backup the tt-rss directory but I have the disk space and I am paranoid so why not back it up?

Nothing wrong with it if it works for you. Just git tracks everything. One thing to think about is the caches. If you use the cache_starred_images plugin those wouldn’t carry over automatically.

I used to do that, but it’s not how I get notified about any other system updates so I changed to a cron job that just checks for me and emails. Just personal perference.

1 Like

Since we’re posting update scripts, here’s mine:

echo killing daemon
./daemonctl stop
mv nohup.out nohup.old
cat nohup.old
sleep 1
echo pulling ttrss
git pull
echo updating config.php

diff config.php-dist-old config.php-dist > config.php.changes
if [ -s config.php.changes ]; then
echo config changes:
cat config.php.changes
cp config.php-dist config.php
cp config.php-dist config.php-dist-old
patch < config.php.patch
if [ $? -eq 0 ]; then
diff -c config.php-dist config.php > config.php.patch
echo patch problems, fix manually
echo updating schema
./update.php --update-schema
echo starting daemon
./daemonctl start

:slight_smile: That is both fair and a really good reason.

The only thing I would criticise is that it does not do any backups whatsoever so you might possibly end up with a corrupted database and no way to recover.

Dunno about @SleeperService, but I take weekly backups anyway so if something does go wrong with an update it’s not a big loss.

Actually, as small as the DB is, should probably do daily…

What’s not mentioned is that my db is sitting on a zfs file system with snapshots taken every 15 minutes, and archived out to hourly, daily, weekly and then monthly. if corruption did occur, it takes less time to roll back than doing a backup would.
stop postgres, zfs rollback [email protected], start postgres.
I love zfs.

While I’ve never had to do that because of anything in ttrss… I have had to do it a few times when I screwed up something in one of the other databases that are in the instance. Because zfs snapshots are atomic, postgres always recovers cleanly. (it’s even documented).

Me too. Best file system around.

:+1: That is a good solution indeed.

I am a total linux scripting newb, but tried your script today and run into an error. Line:
patch < config.php.patch
-> no config.php.patch found. I think you need to create the .patch file first using a diff command?

You should not be using a ad-hoc script unless you understand what it does.

Your problem stem from either a bad copy-and-paste or an erroneous results that happened before. Note that you can run each command by hand and see what happens.

Since we’re posting update scripts, here’s mine:

cp config.php-dist config.php

Dangerous, you might be running on zfs but you are posting this to people who aren’t. If the patch fails then copy/paste users can loose their config. I’d add:

mv -v config.php config.php-orig


diff config.php-dist-old config.php-dist > config.php.changes
if [ -s config.php.changes ]; then

could be simpler, the following works (in bash anyway, also in ksh IIRC):

if ! diff config.php-dist-old config.php-dist > config.php.changes; then


patch < config.php.patch
if [ $? -eq 0 ]; then

Again, could be more direct:

if patch < config.php.patch ; then

Lack of exit codes means cron and schedulers don’t know it failed:

echo patch problems, fix manually

Just add a non-zero exit code so other scripts/schedulers can error check.

FWIW, I do something very similar and after updating the schema I loop thru the plugins from git and pull those as well.

Thanks for sharing your code.

e: and a warning for newb’s might help bootstrap them into your flow:

if [ ! -f config.php.patch ] ; then
   echo "before using this script you need to bootstrap the patch like this:"
   echo "diff -u config.php-dist config.php > config.php.patch"

or something like that. You obviously don’t need that in your script but when you share it would help the next poor soul; which is you intention. Just some thoughts. Thx again.

Given the number of substantive changes to config.php-dist I’ve seen since I started using ttrss, why is this a thing that even needs to be scripted?

Over to Mr. Munroe for the rest of what I had to say…