
=================================================================================
#DEBUG NOTES:
if you get weird errors involving guest passes try incrementing the last guest index
update pacauth_config set cvalue=cvalue+1 where cparameter="lastGuestIndex";


=================================================================================

#on new server:


CUSTCODE=mylibraryname
NEWSERVER=10.1.75.251
OLDSERVER=10.1.75.250

#make .ssh the same
rsync -a /root/.ssh/ /root/.ssh.orig/
rsync -a /var/backups/groovix/snapshots/old-server//root/.ssh/ /root/.ssh/

#grab files from old server:
mkdir -p /var/backups/groovix/snapshots/
rsync -a $OLDSERVER:/var/backups/groovix/snapshots/last/ /var/backups/groovix/snapshots/old-server/

cp /etc/groovix/groovix.conf /etc/groovix/groovix.conf.default
cp /var/backups/groovix/snapshots/old-server/etc/groovix/groovix.conf /etc/groovix/groovix.conf

# this doesn't set everything, mysql still tries to use UTC!
timedatectl set-timezone "America/Chicago"
#be sure to also run
dpkg-reconfigure tzdata

wget http://archive6.groovix.net/groovix-util.deb
dpkg -i groovix-util.deb ; #you will get an error - but proceed with the next command which will fix it
groovix-auto-apt-get -f install
groovix-sources-setup

wget http://util.groovix.net/files/python-mysqldb_1.3.10-2ubuntu1_amd64.deb
dpkg -i python-mysqldb_1.3.10-2ubuntu1_amd64.deb ; #you will get an error - but proceed with the next command which will fix it
apt-get -f install

groovix-auto-apt-get install groovix-server

#install groovix server using 
/var/www/html/groovix/installer/installer.bash

#to help answer questions like custom id and custom pw  see pactime/my_config.py and pactime/server_config.py on old server

edit /etc/cron.d/groovix-server-custom to include all special stuff that was on the old server in /etc/crontab, etc. or just copy file if its current:
cp /var/backups/groovix/snapshots/old-server/etc/cron.d/groovix-server-custom  /etc/cron.d/groovix-server-custom

edit /etc/hosts to have fqdn : 127.0.1.1  CUSTCODE.groovix.net  groovix-server.lan  groovix-server localhost.localdomain


#grab old databases if not already in backup snapshot or snapshot is old
#ON OLD SERVER:
# can look up values ; cat /var/www/html/groovix//global/mylogin.cnf
#ON OLD SERVER# mysqldump --replace --no-create-db --no-create-info -u GXU -pGXP GXDB | gzip  > /tmp/mysql_gxdb.sql.gz
scp $OLDSERVER:/tmp/mysql_gxdb.sql.gz /tmp/ 
# change cmon map positions if coming from old version ( have to gunzip first )
perl -pi -e 's/left:(\d+)px/"left:".int($1*1.50)."px"/eg;s/top:(\d+)px/"top:".int(($1*1.05)-100)."px"/eg;' maps.sql ;
gunzip < /tmp/mysql_gxdb.sql.gz | gxdb

OR if snapshot is current, import into new server from there
#NOTE: might have to clean up old data first, have had some problems due to lines being too long
# see /var/www/html/groovix/pacrez/doc/cleaning_out_old_data.mysql
gunzip < /var/backups/groovix/snapshots/old-server/mysql_gxdb.sql.gz | gxdb

# might have to add id field in gxrelease_txlog
# might have to get rid of webcal_user_layers section in file ( gunzip it, edit it, import it )
# might have to drop table gxrelease_jobs_old; # delete gxrelease_jobs_old section from sql file, then import it, then re-add it: CREATE TABLE gxrelease_jobs_old   SELECT * from gxrelease_jobs;


#only if also serving as a print server:
groovix-auto-apt-get install groovix-print-release




copy any customized files off old server:
- dashboard config.php and header.php
rsync -a /var/www//html/groovix/dashboard/ /var/www//html/groovix/dashboard.default/
cp /var/backups/groovix/snapshots/old-server//var/www//html/groovix/dashboard/config.php /var/www//html/groovix/dashboard/
cp /var/backups/groovix/snapshots/old-server//var/www//html/groovix/dashboard/header.php /var/www//html/groovix/dashboard/

# custom acceptable use pages:
rsync -a /var/backups/groovix/snapshots/old-server//var/www//html/groovix/accept/$CUSTCODE /var/www//html/groovix/accept/$CUSTCODE

- print server/ cups , only if applicable
service cups stop
rsync -a /etc/cups/ /etc/cups.default/
cp /var/backups/groovix/snapshots/old-server/etc/cups/printers.conf /etc/cups/printers.conf
rsync -a /var/backups/groovix/snapshots/old-server/etc/cups/ppd/ /etc/cups/ppd/
service cups start

- gnc setup
rsync -a /var/backups/groovix/snapshots/old-server/var/www/html/groovix/gnc/updates/$CUSTCODE/ /var/www//html/groovix/gnc/updates/$CUSTCODE/

- old stats reports from stats and gxrelease
rsync -a /var/backups/groovix/snapshots/old-server/var/www/html/groovix/stats/custom/ /var/www//html/groovix/stats/custom/
rsync -a /var/backups/groovix/snapshots/old-server/var/www/html/groovix/gxrelease//custom/ /var/www//html/groovix/gxrelease/custom/

- adjust anonymization settings in  /var/www/html/groovix/gxrelease/move_to_old.sql
cp /var/www/html/groovix/gxrelease/move_to_old.sql /var/www/html/groovix/gxrelease/move_to_old.sql.default
cp /var/backups/groovix/snapshots/old-server/var/www/html/groovix/gxrelease/move_to_old.sql /var/www/html/groovix/gxrelease/move_to_old.sql

- files from /etc/groovix like pacauth.conf - get from local client machine if server grabbing gncs
cp /etc/groovix//pacauth.conf /etc/groovix//pacauth.conf.default
cp /var/backups/groovix/snapshots/old-server/etc/groovix/pacauth.conf /etc/groovix//pacauth.conf

if using pacrez, will need pacauth:
chown root.www-data /etc/groovix/pacauth.conf ; # so pacrez can read it


# customized files may be in gnc even if gnc is not enabled on the server, so check on the gnc server at ~/u2017.groovix.net/updates/$CUSTCODE/*server* 

#if using mirrors: 
apt-get install apt-mirror
cp /etc/apt/mirror.list /etc/apt/mirror.list.default
cp /var/backups/groovix/snapshots/old-server/etc/apt/mirror.list /etc/apt/mirror.list
root@groovix-server:/var/www/html# ln -s /mirrors/apt-mirror/mirror/* ./



- in /var/www/html/groovix/pactime/my_config.py duplicates_allowed_user_list=["guest","catalog","gvuser","gxuser","preschool"]
grep duplicates_allowed /var/backups/groovix/snapshots/old-server/var/www/html/groovix/pactime/my_config.py >> /var/www/html/groovix/pactime/my_config.py


- set up backup

- clear out old data to make server run better ( we have backup of old server so this is a great time to do it, maybe wait until after testing stats generation to see if new report matches old  )
	- see /var/www/html/groovix/pacrez/doc/cleaning_out_old_data.mysql

- testing
	- see groovix-server/var/www/html/groovix/common/doc/testing.txt

# reboot !
