For more details on its development status see TRIM
Table of contents
What
- A combination of shell and PHP scripts to install, update, backup, restore and monitor (check security of) a large number of Tiki installations (instances).
- TRIM facilitates/automates the operations you would normally do by logging into each server.
- A great tool if you want to setup a WikiFarm
- It is not a script to update your Linux or MySQL installation (but it may one day do some server checks to see if your Apache, PHP, MySQL, GD, etc. versions are OK).
- Originally developed for Tiki, it was designed so it could be ported/used for just about any php/mysql application which has CVS or SVN as a source. If you want to port to a different app, let's work together!
How it works
TRIM is installed on a master server. TRIM then connects by SSH (and more recently via FTP) to various servers and, via a wizard (you answer the questions interactively), permits you to manage various instances of Tiki. You can install, upgrade, backup, check the file integrity and do various other things. Some actions can be run unattended on a cron job.Limitations
- Although CVS can work, it is not supported and bugs will not be fixed. The Tiki community has been using SVN for a long time now.
- FTP support has been added, however, you can run into memory limitations (outside of TRIM's control)
Alternatives
If you have a large number of Tiki installations, you could use MultiTiki where all files (php/tpl/etc) are shared amongst several domains (but you can have .css and .tpl which override for your domain) but each domain has a distinct DB. TRIM is different where each domain is totally independent. Distinct database and distinct files and can be on different hosts.Advantages of TRIM over MultiTiki
- With TRIM, each instance can be on totally different servers or on various directories on the same server, so you can easily scale to as few or as many servers as you want.
- Once an instance is in a MultiTiki, it's a little tricky to extract it. For example, it's easier to provide a backup of just one instance, using TRIM.
- If you have multiple domains and need to provide distinct access for each (emails, ftp accounts, access to logs, etc.), it can be easier to have distinct server space.
- With MultiTiki, if you have a security issue, all your Tikis are potentially compromised because they share the same files. (even for the Tikis that have not enabled the unsafe feature)
- With TRIM, you can pick & choose which Tikis to upgrade. With MultiTiki, all the instances get the upgrade. Even if they don't need the bug fixes or enhancements, they are still at risk of being affected by a regression. So all instances need to be checked after each upgrade.
- This takes a lot of time. And then, you can introduce issues for projects that were quite happy with the previous version. They didn't need new stuff, but inherited some problems.
- With TRIM, you can modify the templates/*.tpl files and still use the merging features of cvs/svn to take advantage of the enhancements to the main code base (There could be conflicts to manually resolve during upgrades though). Using multiTiki, you must put all changes in a separate directory and can't easily benefit from improvements to the main code base.
- TRIM handles offsite backups
Advantages of MultiTiki over TRIM
- Uses less disk space
- Can upgrade hundreds of Tikis in one operation
- MultiTiki has been developed and refined for years and is used in production, whereas TRIM is relatively new and still in development
-
TRIM requires SSH accessTRIM can now work via FTP, whereas maybe MultiTiki can be run just with FTP. Depending on your server, you may have a lot of permissions to change by FTP though. -
TRIM requires more things on the server (sqlite, svn, etc)not anymore, you can use FTP mode and heavy work is done on TRIM master, and result is pushed to the TRIM instance. - MultiTiki has a web-based interface
What if I want to share data between instances?
Sharing data between Tiki instance is not specific to TRIM. If you want to share logins, groups and preferences throughout many Tiki sites, you can use InterTiki.License
LGPL, like the rest of TikiDocumentation
Here is a brief explanation of the basic commands that can be used. All commands follow a wizard pattern.make instance
Adds an instance to be managed by TRIM. Trim attempts to perform various operations from this point:- Share an RSA key to connect to the remote host in the future
- Make a few verifications on remote host
- Detect the application installed remotely and the version
- If nothing is installed, propose to install something
You will be prompted to enter a pass phrase. If you enter one, you will be prompted every time you use TRIM. Unattended backups and security checks will not be possible.
The installation process will ask to create a database and user for Tiki. To do this, root access on the MySQL database (or user with similar privileges) is required. Otherwise, database settings can be entered manually (The database needs to have been created before in cPanel, webmin or similar).
make check
This is somewhat equivalent to a secdb check, except that it's safer because it's made from a trusted host and will take your custom modifications on host into consideration. Upon first run, the check will ask where it should fetch the hashes from.- source : obtain the hashes from the official repository. After setting up the expected hashes, a check will be performed.
- current : use the files currently online as the source of hashes. If this is a recent install, this may be safe. However, if the host was already compromised, hacks will be undetected.
- skip : Move on for now
When files are altered, added or removed, TRIM will prompt with various solutions.
- For modified files, it will allow to view the changes that were made and propose to accept or reject them. Rejecting changes will fetch a copy of the file from the repository.
- For added files, it will be possible view the file and then accept or reject it. Rejecting the file will remove it from the remote host.
- Removed files will allow to accept or reject the removal. Rejection will fetch a copy from the repository.
make update
Allows to update a CVS/SVN instance (cvs up/svn up) and update the file hashes accordingly. It also performs the database update. The hash verification/update may prompt with some files containing conflicts if modifications were made on the instance.During the update process, the instance is disabled using a .htaccess file (previous one is preserved), making the site unavailable until the update is completed.
To setup automated updates
run:php scripts/setupupdate.php
Do not pick the same time as automatic backup!
make upgrade
Similar to update. Requests for the branch to switch to over the update. You will have several choices of branches. Please note that you should NOT downgrade as Tiki doesn't support a downgrade database script. An upgrade is a one-way street! You should make a backup before you upgrade so you can return to this version if issues arise.make convert
Converts an instance from CVS BRANCH-1-9 to SVN branches/2.0.- All script customizations will be lost
- Database, img/wiki and img/wiki_up are preserved
make fix
Run setup.sh on the remote host using automated parameters. It should work in most cases. If the command proposed my setup.sh without parameters or super user rights are required, you should connect to the remote host manually using `make access`.make access
Opens a shell to the remote host. Because TRIM manages all your connections, using this command simply avoids needing to remember passwords.make watch
Set-up a cron job on the TRIM master to perform the Hash check (make check) automatically every day. The script will prompt for a contact email address to notify with the log in the case of a suspicious file change (which could be an intrusion or someone who legitimately changed a file on the server) and the time at which the script should run.make backup
What can go wrong and how should this script protect me?- My host disappears
- A vandal messes up my files
- User error (oups, I erased some files)
TRIM performs a complete backup of the Tiki instance. The backup includes all files on remote host (including user files and files stored out of the web root) and a dump of the database. Each backup is archived in the TRIM_ROOT/backup/archive folder as a .tar.bz2 file. The backup file contains:
- manifest.txt : Indicates where folders were located on the remote host
- database_dump.sql : Self-explanatory
- a-f0-9{32} : Folders named using a hash. Content of the folders on remote host. The manifest.txt file lists these hashes.
Archives are cleaned up after each run. The rules are the following:
- Backups made on the first of any month are kept forever.
- Backups made on Sunday are kept for 31 days.
- Daily backups are kept for a week.
On your first backup, you may get a harmless error message
rm: cannot remove `/home/trim/xyz/backup/1/manifest.txt': No such file or directory
To setup automated backups
run:php scripts/setupbackup.php
Do not pick the same time as automatic update!
make restore
You can restore on a blank install. To make a blank install, just do make instance but cancel when TRIM offers you to install Tiki.make delete
Delete the instance via the command line (you could also do via the web interface). This does NOT delete your Tiki. It just deletes the instance connection to it.make enablewww
Activate the TRIM Web Administration. The script asks a few questions and changes some permissions.Rewrite rules are necessary for TRIM Web Administration
[+]make viewdb
For debug purposes.make detect
For debug purposes.Requirements
- PHP 5.x with SQLite extension (on master server) (uses SQLite 2.1 format)
- PHP 4.x should be OK for remote servers.
- PHP Command Line Interface (PHP-CLI) on both master and remote servers
- Shell (SSH) access on master and remote (eventually, it should work on remote servers with only FTP)
- Both master and instances can be shared hosting as long as you have SSH access. It is recommended that the master be installed on a very safe machine because it has SSH access keys to all your instances.
- Rewrite rules (on master server) are necessary for TRIM Web Administration
Shell commands/scripts
- make
- subversion (svn) (1.10, 2.x and 3.x sites use svn)
- cvs (assuming you'll be maintaining some 1.9x sites via CVS)
- php5-cli (This is the command line version of PHP, which is not always installed)
- sqlite (This is the database where TRIM will store data about the various instances)
- php5-sqlite (extension)
- php5 (for webtrim)
- cron (optional, to automate unattended tasks)
- rsync (for backups)
- sendmail (to send you email notifications of changes to your files)
- bzip2 (for backups)
To restore backups on TRIM (for testing)
- ssh
- phpmysql
ext/ssh2
ext/ssh2 is not mandatory, but highly recommended to speed up TRIM. It will also avoid many weird error messages and it is much stabler. Without it, it should work but some things may not.
To install it under Debian or Ubuntu:
# sudo apt-get install libssh2-php
If that didn't work:
# sudo apt-get install php5-dev libssh2-1-dev php-pear
see http://pecl.php.net/ssh2 for latest version number
# sudo pear install pecl/ssh2-0.11.0
If you get questions, just press "Enter" to accept the defaults.
add to the end or uncomment extension=ssh2.so in php.ini
# sudo nano /etc/php5/cli/php.ini
to test if it works, look for ssh2
# php -m
Related
http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/
Linux
To install all of these under Debian or Ubuntusudo apt-get install make subversion cvs php5-cli sqlite php5-sqlite php5 cron rsync sendmail bzip2
Windows
There are no current plans for TRIM (the master) to work on Windows. So you should use something one of options below. With upcoming FTP support, Windows on the instances should made easier. Related: Platform independenceUbuntu on Windows
- Download and install Ubuntu on Windows solution
- Follow instructions for Ubuntu (apt-get install...)
Options
- How to install Ubuntu Linux on Windows using VirtualBox
- andLinux is a complete Ubuntu Linux system running seamlessly in Windows 2000 based systems (2000, XP, 2003, Vista; 32-bit versions only).
- PortableUbuntu
Mac
On a Mac, you'll need something like MacPorts. The package names may vary a bit.sudo port install make sudo port install cvs sudo port install php5-sqlite3 ...
How to download and use
1- Get TRIM via SVN (to the current directory)svn co https://tikiwiki.svn.sourceforge.net/svnroot/tikiwiki/trim .
2- Make an instance
make instance
(or just type make and you will get choices like make check, make update, etc)
If TRIM is not detecting php5-cli (It's important to have this)
To test:
$ php -v
This should give you the php version of your default command line version. Ex.:
PHP 4.4.9 (cli) (built: Sep 17 2008 12:02:18)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend TechnologiesIn this case, you should manually edit the file
MakefileReplace:
PHP = php5 -d memory_limit=256M
with something like: (ask your host)
PHP = /usr/local/php5/bin/php -d memory_limit=256M
| Question | note |
| Instance name | Just a pretty name for the Tiki instance |
| Contact email | Email of person in charge of this Tiki instance |
| Web root | full path, no trailing slash (/) |
| Web URL | full URL, with http |
| Working directory | You can use /tmp or create/use a directory on your remote server. Full path, no trailing slash (/) |
| SSH host name | domain to connect by SSH |
| SSH port | if you are not using the usual port 22 |
| SSH user | username to connect by SSH |
When make instance reports:
Branch tags/1.10.0 was found. If this is not correct, enter the one to use :
type: branches/1.10
Example
example
[avantech]$ make instance /usr/local/php5/bin/php -d memory_limit=256M scripts/addinstance.php Default editor used (vim). You can change the EDITOR environment variable. Default diff used (diff). You can change the DIFF environment variable. Instance name : RTO test Contact email : <hidden> Web root : /home/rto/public_html Web URL : http://rto.ourwiki.net Working directory : /home/rto/temptrim Instance information saved. SSH host name : rto.ourwiki.net SSH user : rto The authenticity of host 'rto.ourwiki.net (<snip>)' can't be established. RSA key fingerprint is <snip>. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'rto.ourwiki.net,<snip>' (RSA) to the list of known hosts. rto@rto.ourwiki.net's password: Testing connection... Were you asked for a password? [yes|no] no warning: locate: warning: database /var/lib/slocate/slocate.db' is more than 8 days old Branch tags/1.10.0 was found. If this is not correct, enter the one to use : branches/1.10
To restore backups on TRIM machines
We want to test that the backups are indeed working so we need a fully functioning php-mysql environment. By installing phpMyAdmin, we should get this. We also want SSH because TRIM connects via SSH to restore these backups, the same as it would connect anywhere.To install necessary software under Debian or Ubuntu:
Install what is needed to run php-mysql apps and for TRIM to connect
# sudo apt-get install phpmyadmin ssh
After the install, visit http://localhost/phpmyadmin/
An example of creating an instance (where to restore to)
trim@trim:~/avantech-trim$ make instance php5 -d memory_limit=256M scripts/addinstance.php Default editor used (vim). You can change the EDITOR environment variable. Default diff used (diff). You can change the DIFF environment variable. Connection type [ssh|ftp] : ssh Host name : localhost User : trim Instance name : [localhost] Contact email : Web root : [/home/trim/public_html] /var/www/restoredfromtrim/ Web URL : [http://localhost] http://localhost/restoredfromtrim Working directory : [/home/trim/trim_temp] /tmp Instance information saved. The authenticity of host 'localhost (::1)' can't be established. RSA key fingerprint is <snip>. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'localhost' (RSA) to the list of known hosts. trim@localhost's password: Testing connection... After successfully entering your password, were you asked for a password again? [yes|no] no Detecting remote configuration. No applications were found on remote host. Which one do you want to install? (none to skip) [0] tikiwiki >>> No instance to install. trim@trim:~/avantech-trim$
