CPanel

Various CPanel Articles and Notes - more a notepad than best methods. As I transfer to click-administration after sometime of webmin + vi, notes are needed.

Backup or Transfer Accounts

Use this to move/copy users between cpanel servers - last time when moving users by hand it took 2 days to move what I can now in about 10 minutes (exclude tar.gz time) and more importantly for users, passwords remain the same.

Take backup of the accounts using the following script: ( in source server)
# /scripts/pkgacct username
This will create a backup file under /home with name cpmove-username.tar.gz

# /scripts/restorepkg username

From http://sakafi.wordpress.com/tag/cpmove/

Bind Zones

Bind zones are ok to be edited directly: increment the serial number, verify changes with service named check, then if all is ok, service named restart - tried to use rndc reload example.com, but it gave some error.

www2 for a domain

To get www2 to stick for an apache server config w/o any other mods, and for testing, I added as a server alias to the httpd.conf file, then ran /usr/local/cpanel/bin/apache_conf_distiller --update, then /usr/local/cpanel/bin/build_apache_conf

Exim - anti-spam delays and subject rewrite

These are a couple things I tweaked in exim to help with the spam - mind this is a low volume server - so your mileage may vary.. I am new to Exim, there are surely better ways to do this, but immediately helped out without getting deep into exim.

1. Adding some delays to the SMTP transaction - this drops the impatient spammers...

At the end of the acl_mail block add a delay for everyone

    accept
        delay = 5s

Add this to the end of the acl_connect block

# Lets delay everyone for now to 8s for connecting...
    accept
        delay = 8s


2. Change the subject for spam emails - without digging into Spam Assassin configs and the cpanel way things are done, emails that were scored as spam - wanted "spam" prepended to the subject. Added this snippet below to help the case - set this in my own /etc/custom_exim_system_filter file. This is global on the server for incoming email. Additionally, I have seen emails over 4 "pluses" are definitely spam the past 2 weeks since implemented this.
if $message_headers matches "X-Spam-Bar: \\\\+\\\\+\\\\+\\\\+" then 
  headers add "Old-Subject: $h_subject:"
  headers remove "Subject"
  headers add "Subject: *Spam*  $h_old-subject"
  headers remove "Old-Subject"
endif
Cpanel was overwriting my changes to the default file, so copied, added this chunk then configured cpanel to use my version of the file - again, to prevent overwriting when cpanel updates.

Import all mysql datbases for a cpanel user

A long time ago my cpanel server was a mysql slave - I had not "deconfigured" this and tonight upon restart wiped out about 15 databases - mostly mine, plus a couple others. I restored all of them from hour old backups I just made. If I had not just done the backups, I'd lost a day or so..

Again, importance of backups and for "this is just a minor tweak" and "just a quick restart" .. yeah. Backup first.

So, summary was to disable being a slave server, then tar -xzf the backups, re-create the DB's, restore the DB's, restore permissions..

  1. Disable the slave server - do this with mysql stopped.
    # mv master.info mcmaster.infooo
  2. Restart the server and verify the slave status - nothing...
    root@vps2 [//home/unpack/cpmove-user/mysql]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 396
    Server version: 5.0.77-community MySQL Community Edition (GPL)
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql> show slave status\G
    Empty set (0.00 sec)
    
    mysql> quit
    Bye
    

    Thanks to Sun MySQL Forum at the MySQL Forum

  3. Unpack your cpmove backup - using /scripts/pkgacct to backup clients - makes for very easy restore..
  4. cd to their unpack, for example /home/unpack/cpmove-user/mysql and I ran this command to blitz create all the user databases for the user:
    for sql in `ls user*`; do sql=`echo $sql | sed 's/\.sql//'`; echo "create database $sql; >> makedb.sql"; done; mysql < makedb.sql
  5. With the DB's created, import the data:
    for sql in `ls user*`; do sqldb=`echo $sql | sed 's/\.sql//'`; mysql $sqldb < $sql; done
  6. Now the DB's restored, restore the permissions from the file one directory up; mysql.sql
    # mysql < ../mysql.sql 

    This restored about 15 databases very quickly with original permissions, passwords and I was able to get right back to work.