Backups are made every night from each clinic and the backup files are stored on the file server. All backup files on the file server are daily backed up by Veeam Backup onto tape. Any data changes can be tracked by comparing the backups.
1. Linux
1.1. Build
-
Install Git.
-
Install JSHint.
-
Install JSLint.
-
Install PostgreSQL.
-
Log in as smru on the tbhf-anc-mrm server.
-
Enter the following commands at a Command Line.
# Packages needed for data dictionary. sudo apt-get install default-jre sudo apt-get install graphviz sudo apt-get install p7zip p7zip-full p7zip-rar # Get source code from GitHub repository. mkdir -p ~/github/git/delta-software-labs cd ~/github/git/delta-software-labs git clone https://delta-software-labs@github.com/delta-software-labs/ANC-Application.gitcd ~/github/git/delta-software-labs/ANC-Application make make clean make clean-all make check make all # Copy packages to SMRU repository server. make publish PUBLISH_TARGET=delta@tbhf-anc-mrm:/home/delta -
When using WSL, then ignore the following warning.
WARNING: could not flush dirty data: Function not implemented
1.2. GPG Key
-
Log in as smru on the tbhf-anc-mrm server.
-
Enter the following commands at a Command Line with root privileges.
# List GPG keys. gpg --list-secret-keys gpg --list-keys # Delete any GPG keys. gpg --delete-secret-keys <id> gpg --delete-keys <id> # List GPG keys. gpg --list-secret-keys gpg --list-keys # Cleanup. rm -rf ~root/.gnupg
-
Enter the following commands at a Command Line with root privileges.
mkdir -p ~root/.gnupg chmod 700 ~root/.gnupg if ! grep -q "^cert-digest-algo SHA256" ~root/.gnupg/gpg.conf; then echo "cert-digest-algo SHA256" >> ~root/.gnupg/gpg.conf fi if ! grep -q "^digest-algo SHA256" ~root/.gnupg/gpg.conf; then echo "digest-algo SHA256" >> ~root/.gnupg/gpg.conf fi # Skip next line on Debian 8 as "pinentry-mode loopback" option # is not supported by gpg version 1.4.18. if ! grep -q "^pinentry-mode loopback" ~root/.gnupg/gpg.conf; then echo "pinentry-mode loopback" >> ~root/.gnupg/gpg.conf fi chmod 600 ~root/.gnupg/gpg.conf cat ~root/.gnupg/gpg.conf # Make sure to have enough entropy. apt-get install haveged # Create file to generate key. file="pgp-key-generation" # Don't use single quotes around EOF to allow interpreting variables. cat << EOF | sed 's/^ //' | tee "$file" > /dev/null %echo :: Generating a basic OpenPGP key. Key-Type: RSA Key-Length: 4096 Key-Usage: sign Subkey-Length: 4096 Expire-Date: 0 Name-Email: smru-it@shoklo-unit.com Name-Real: SMRU-IT %commit %echo :: Done. EOF # Generate GPG key without any questions. gpg --batch --gen-key pgp-key-generation # Use level 2 password. tree ~root/.gnupg ls -al ~root/.gnupg # List GPG keys. gpg --list-secret-keys gpg --list-keys # Retrieve key id. KEYID=$(gpg --list-keys --with-colons | awk -F: '/pub:/ {print $5}') echo $KEYID # Export key. rm -f SMRU.key gpg --armor --output SMRU.key --export $KEYID
1.3. SMRU Repository
-
Log in as smru on the tbhf-anc-mrm server.
-
Enter the following commands at a Command Line with root privileges.
apt-get install reprepro # Cleanup. rm -rf /var/www/html/debian # Create repository directories. mkdir -p /var/www/html/debian/conf # Store GPG key in repository. cp -a SMRU.key /var/www/html/debian/conf # Retrieve key id. KEYID=$(gpg --list-keys --with-colons | awk -F: '/pub:/ {print $5}') echo $KEYID FILE="/var/www/html/debian/conf/distributions" # Don't use single quotes around EOF to allow interpreting variables. cat << EOF | sed 's/^ //' | tee "$FILE" > /dev/null Origin: SMRU Label: ANC Codename: anc Architectures: amd64 Components: main Description: SMRU ANC Application SignWith: $KEYID DebOverride: override.anc EOF FILE="/var/www/html/debian/conf/override.anc" # Don't use single quotes around EOF to allow interpreting variables. cat << EOF | sed 's/^ //' | tee "$FILE" > /dev/null anc Priority optional anc Section net EOF cd /var/www/html/debian reprepro export # Use level 2 password. packages=$(ls /home/delta/smru-*.deb) for package in "$packages"; do printf "$package\n"; done for package in "$packages"; do reprepro includedeb anc $package; done # Use level 2 password. tree /var/www/html/debian
1.4. Installation
-
Log in as smru.
-
Install Apache 2.
-
Install PHP.
-
Install PostgreSQL.
-
Enter the following commands at a Command Line with root privileges.
# Cleanup. apt-key list apt-key del <id> # Import GPG key. wget -O - http://tbhf-anc-mrm/debian/conf/SMRU.key | sudo apt-key add - # List apt keys. apt-key list rm -f /etc/apt/sources.list.d/smru.list echo "deb http://tbhf-anc-mrm/debian/ anc main" > /etc/apt/sources.list.d/smru.list -
Enter the following commands at a Command Line.
sudo apt-get update sudo apt-get install smru-cerise-framework sudo apt-get install smru-anc-application sudo apt-get install smru-anc-data-dictionary sudo apt-get install smru-anc-tools
1.5. Configuration
-
Log in as smru.
-
Enter the following commands at a Command Line.
CLINIC=$(hostname | sed -e 's/^.*-//' | tr '[:lower:]' '[:upper:]') sudo smru-clinic-setup anc-db $CLINIC -
Contents of the ~delta/anc-db.sql file.
UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'Guest'; UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'SMRU'; UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'PP'; UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'Administrator'; UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'IT'; UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'Lab'; UPDATE "Users" SET "Active" = 1, "Password" = MD5('********') WHERE "Name" = 'Doctor'; -
Replace the asterisks by the appropriate passwords in the ~delta/anc-db.sql file.
-
Enter the following commands at a Command Line.
chmod 600 ~delta/anc-db.sql vdir ~delta/anc-db.sql -
Contents of the ~delta/anc-db.ini file.
[database] pass = "********" [debug] pass = "********" [demo] pass = "********" [desktop] pass = "********" [laptop] pass = "********"
-
Replace the asterisks in the [database] section by the level l2 password in the ~delta/anc-db.ini file.
-
Replace the asterisks in the other sections by the appropriate passwords in the ~delta/anc-db.ini file.
-
Enter the following commands at a Command Line.
vdir ~delta/anc-db.ini chmod 640 ~delta/anc-db.ini sudo chown delta:www-data ~delta/anc-db.ini vdir ~delta/anc-db.inicd ~/github/git/delta-software-labs/ANC-Application ./symlinks-undo ./symlinks-make vdir /var/www/html vdir /var/www/html/anc-app/cd ~delta/github/git/delta-software-labs/ANC-Application scp -p delta@10.10.1.2:/tmp/2017-08-05-tbhf-anc-mrm-anc-entire.bak . DB=anc-app PSQLOPTIONS="--no-psqlrc --pset pager=off --quiet --set ON_ERROR_STOP=1 --single-transaction" sudo cp -a smru-anc-tools/bin/smru-db-create /usr/local/bin sudo cp -a smru-anc-tools/bin/smru-db-delete /usr/local/bin sudo cp -a smru-anc-tools/bin/smru-db-restore /usr/local/bin sudo chmod a+x /usr/local/bin/smru-db-create sudo chmod a+x /usr/local/bin/smru-db-delete sudo chmod a+x /usr/local/bin/smru-db-restoresudo /etc/init.d/apache2 restart <????> sudo service postgresql restart <????> -
Enter the following commands at a Command Line.
smru-db-restore $DB 2017-08-05-tbhf-anc-mrm-anc-entire.bak -
When using WSL, then ignore the following warning.
WARNING: could not flush dirty data: Function not implemented
-
Enter the following commands at a Command Line.
// psql $PSQLOPTIONS --dbname $DB --file smru-anc-tools/share/update-to-193.sql psql -c 'REFRESH MATERIALIZED VIEW viewmat_enrolment' -d $DB -
Browse to http://10.10.1.2/anc-app.
-
Enter the following commands at a Command Line.
sudo vi /var/log/apache2/error.log
1.6. Online Help
-
Log in as smru on the tbhf-anc-mrm server.
-
Enter the following commands at a Command Line.
cd /var/www/html/docs/help-pages scp -p anc-application.html root@tbhf-anc-mrm:/var/www/html/anc-app scp -p anc-application.html root@tbhf-anc-mkt:/var/www/html/anc-app scp -p anc-application.html root@tbhf-anc-mla:/var/www/html/anc-app scp -p anc-application.html root@tbhf-anc-wpa:/var/www/html/anc-app scp -p anc-application.html root@tbhf-anc-msl:/var/www/html/anc-app
1.7. Migrate ANC Application
Copy the ANC Application from one computer to another computer.
Create database and file system backups on the source computer and copy them onto a USB device and restore the database and file system on the destination computer.
-
Log in as smru on the source computer.
-
Enter the following commands at a Command Line.
# Set database name depending on clinic. db=anc-mkt db=anc-mla db=anc-msl db=anc-wpa # Stop database and web servers. sudo /etc/init.d/apache2 stop # Backup database. smru-db-backup $db /tmp cd / # Backup file system. sudo tar cfz /tmp/anc-app.tgz /var/www/html/anc-app sudo tar cfz /tmp/anc-data-dictionary.tgz /var/www/html/anc-data-dictionary # Start database and web servers. sudo /etc/init.d/apache2 start -
Copy the backups from the /tmp folder to the USB device.
-
Log in as smru on the destination computer.
-
Copy the backups from the external USB device to the /tmp folder.
-
Enter the following commands at a Command Line.
# Set database name depending on clinic. db=anc-mkt db=anc-mla db=anc-msl db=anc-wpa # Set date. date=$(date '+%Y-%m-%d') # Set host name. host=$(hostname -s) # Stop database and web servers. sudo /etc/init.d/apache2 stop # Restore database. smru-db-restore $db /tmp/$date-$host-$db.bak cd / # Remove any previous ANC Application. sudo rm -rf /var/www/html/anc-app sudo rm -rf /var/www/html/anc-data-dictionary # Restore file system. sudo tar xfc /tmp/anc-app.tgz sudo tar xfc /tmp/anc-data-dictionary.tgz # Start database and web servers. sudo /etc/init.d/apache2 start
1.8. Restore backup
In case the ANC number is wrong due to a corrupt database the latest backup should be restored as soon as possible.
-
Log in as smru on the tbhf-anc-mkt / tbhf-anc-msl / tbhf-anc-wpa server.
-
Enter the following commands at a Command Line.
# Set database name depending on clinic. db=anc-mkt db=anc-mla db=anc-msl db=anc-wpa # Set date. date=$(date '+%Y-%m-%d') # Set host name. host=$(hostname -s) # Stop web server. sudo /etc/init.d/apache2 stop # Show all backups. vdir ~delta/backups # Show databases. psql --list # Backup corrupt database. smru-db-copy $db $db-err # Show databases. psql --list # Restore database. sudo smru-database-restore ~delta/backups/$date-$host-$db.bak $db # Start web server. sudo /etc/init.d/apache2 start
2. Fix Primary Key Issues
-
Log in as smru on the tbhf-anc-mrm ANC server.
-
Enter the following commands at a Command Line.
check-anc-conflicts # Delete record at remote site. psql -h tbhf-anc-wpa -d anc-wpa -c "DELETE FROM \"tblPregnancy\" WHERE \"PID\" = '441030';" psql -h tbhf-anc-mkt -d anc-mkt -c "DELETE FROM \"tblPregnancy\" WHERE \"PID\" = '145386' AND \"Nr\" = 1;" psql -h tbhf-anc-wpa -d anc-wpa -c "DELETE FROM \"tblPregnancy\" WHERE \"PID\" = '417306' AND \"Nr\" = 1;" psql -h tbhf-anc-wpa -d anc-wpa -c "DELETE FROM \"tblPregnancy\" WHERE \"PID\" = '447545' AND \"Nr\" < 3;" # Delete record at Mae Ramat on tbhf-anc-mrm. psql -d anc-wal -c "SELECT * FROM \"tblPregnancy\" WHERE \"PID\" = '138585';" psql -d anc-wal -c "DELETE FROM \"tblPregnancy\" WHERE \"PID\" = '138585';"
3. Usage
Todo