UgandaEMR User Manual
  • Introduction
  • Terminologies
  • System Setup and Configuration
    • UgandaEMR 1.x Installation
    • UgandaEMR 2.x Installation
    • UgandaEMR 3.x Installation
    • Linux Installation
    • Post-installation Configuration
  • Backup and Restoration
    • Linux backup
  • Upgrading UgandaEMR
    • Trouble Shooting
  • Configuring your installation
  • Managing User Accounts
  • Provider Management
    • Creating a New Provider
    • Making an existing user a provider
  • Patient Management
    • Finding Patient
    • Patient Registration
  • Fingerprint
    • Configuration
    • Search by Patient Fingerprint
    • Add Patient Fingerprint
  • Entering Client Information
    • HIV Testing Services Client Card
    • ART Card
    • HIV Exposed Infant Card
    • HIV Counseling and Testing Client Card
    • Maternal and Child Health Cards
    • Safe Male Circumcision
    • Outpatient Form
  • Reporting
    • UgandaEMR Reports
    • Cohort Builder
    • Data Export
    • Sending Report to DHIS2
    • Sending Metrics Report
    • Audit tool Reports
    • Troubleshooting Report Tips
  • Data Quality Checks
  • Patient Provider Notifications
    • Configurations
    • Message Customization
    • Patient Enrollment
    • Patient De-registration
  • Patient Flags
  • Program Workflows
    • Differentiated Service Delivery Models (DSDM)
    • HIV Recency Testing
    • ART Regimen Lines
    • Tuberculosis
    • COVID19
  • Troubleshooting Tips
  • Uninstalling UgandaEMR
    • Unistalling UgandaEMR older versions
  • Point of Care (POC)
    • Installation and Configuration
      • Roles
    • Work Flows
      • Reception
      • Triage
      • Clinician
        • HIV Clinic
      • Laboratory
      • Pharmacy
  • Data Exchange
    • ART Access Integration
    • Viral Load Integration
    • Send Aggregate Reports
    • Patient Data Upload
      • Uploading Viral Load Results
  • UgandaEMR Mobile
    • Introduction
    • Download Patients
  • Release Notes
    • 1.0.14
    • 1.0.16
    • 1.0.17
    • 2.0.0
    • 2.1.0
    • 3.0.0
    • 3.0.4
    • 3.1.0
    • 3.1.3
    • 3.2.0
    • 3.3.0
    • 3.3.7
    • 3.4.1
Powered by GitBook
On this page
  • LINUX MYSQL DATABASE BACKUP USING AUTOMATIC SCHEDULED JOBS
  • SENDING BACKUPS TO REMOTE SERVER

Was this helpful?

  1. Backup and Restoration

Linux backup

LINUX MYSQL DATABASE BACKUP USING AUTOMATIC SCHEDULED JOBS

  1. Ensure mysqldump function is available by typing

mysqldump - -version

  1. If mysqldump is installed, proceed to step 3. If not please install mysqldump using

sudo apt install mariadb-client

  1. Install Zip

sudo apt install zip

  1. Next, we are to write a script to backup database using mysqldump

  2. Create a new directory for storing the backups:

sudo mkdir /var/backups/mysql

  1. Create a new shell script that performs the backup and compression:

sudo nano /usr/local/bin/mysql-backup.sh

  1. In the text editor, paste the following code:Adjust where necessary

    # Set the database credentials
    
    DB_USER="openmrs"
    
    DB_PASS="openmrs"
    
    DB_NAME="openmrs"
    
    # Set the backup filename and location
    
    BACKUP_DIR="/var/backups/mysql"
    
    BACKUP_FILE="$BACKUP_DIR/openmrs-backup-$(date +%Y%m%d-%H%M%S).sql"
    
    COMPRESSED_FILE="$BACKUP_DIR/openmrs-backup-$(date +%Y%m%d-%H%M%S).zip"
    
    # Create the backup file ensure to change your mysql.sock if it is different from the default one
    
    mysqldump -u "$DB_USER" -p"$DB_PASS" -d "$DB_NAME" > "$BACKUP_FILE"
    
    # Compress the backup file
    
    zip -r "$COMPRESSED_FILE" "$BACKUP_FILE"
    
    chmod 666 $COMPRESSED_FILE
    
    # Remove the original backup file
    
    rm "$BACKUP_FILE"
  2. Save and close the file (Ctrl+X, Y, Enter).

  3. Make the script executable:

sudo chmod +x /usr/local/bin/mysql-backup.sh

  1. Set up a weekly cron job to run the backup script:

sudo crontab -e

  1. Add at the end of the file the following line:

0 16 \* \* \* /usr/local/bin/mysql-backup.sh

Above example (0 16 * * *) means this job runs every day at 16:00

Change the timing of the cron job to suite you and save.

Done .

SENDING BACKUPS TO REMOTE SERVER

In case you want to send backups to a remote server REQUIREMENTS :

  • REMOTE SERVER

  • REMOTE USER

  1. Generate SSH keys on your local server(facility machine) if you haven't already done so:

ssh-keygen -t rsa

  1. Press Enter to accept the default file location and passphrase or specify your preferred options.

  2. Copy the public key to the remote server:

ssh-copy-id user@remote_host

  1. This will prompt for remote host password

  2. Test the connection using ssh user@remote_host to login with out password. If successful, then our local machine is now able to accessible the remote without password

  3. Edit the mysql-backup.sh file to add the following code at the end of the file

#Variables

REMOTE_USER="remoteuser" # Remote server username

REMOTE_HOST="remote-server IP" # Remote server hostname or IP address

REMOTE_DIR="//path/to/backups/" # Path to remote directory (change as needed)

scp "$COMPRESSED_FILE" "$REMOTE_USER"@"$REMOTE_HOST":"$REMOTE_DIR"

if \[ $? -eq 0 \]; then

echo "File $filename transferred successfully."

else

echo "Error: Failed to transfer file $filename."

fi
  1. Save the file and test it by running sudo sh /path/to/mysql-backup.sh

  2. File transferred successfully.

PreviousBackup and RestorationNextUpgrading UgandaEMR

Last updated 1 year ago

Was this helpful?