Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Author: Nyle Davis Created 21-10-05
- # Purpose: 1.) Backup all MySQL DBs/Tables, 2.) Purge LAMP Stack,
- # 3.) Re-Install LAMP Stack & PostGres, 4.) Re-install Data.
- # File: lamp-replace.sh
- # Source: The source of this code is from other working backup scripts
- # and from the online source at:
- # codegrepper.com/code-examples/shell/how+to+uninstall+lamp+
- # server+in+ubuntu+18.04
- # Tester: The source of this code is tested with:
- # shellcheck.net
- # Run with command
- # CMD: bash ../Scripts/MySQL/lamp-replace.sh
- # Script is CRON capable
- # Declare the functions:
- function mysql_bup () {
- # Backup MySQL
- # May have to additionally manually backup the phpmyadmin option DB as that
- # MySQL management DB sometime does not work/backup correctly.
- # This may require using PHPmyAdmin or MySQL Work Bench.
- echo "Backing up the DBs!";
- bkpath='/3T/backups/LAMP/'; # Declare the backup path
- dbuser=$USER; # Get the System user
- dbpass='nomened.1497'; # Get the DB password
- dbpath='/usr/bin'; # Declare the system path
- dbopts='--all-databases --events -A -C -f';
- mybupd="${bkpath}MySQL/"; # Declare MySQL backup path
- flname="mysql_dump_(`eval date +%Y-%m-%d`).tgz"; # Declare the backup file
- fullnm="${mybupd}${flname}"; # Declare full backup file
- echo "F=> ${fullnm}";
- mkdir -p ${bkpath}; # Create the backup path
- ls -al ${bkpath}; # Show the backup path
- if [[ -f $fullnm ]]; then # Remove old backup file(s)
- rm -f ${fullnm};
- else # Create the new backup file
- curdir=$(pwd); # Could not make this work outside
- cd ${bkpath}; # out of the if/else logic because
- touch ${flname}; # it has to be in the target dir.
- GZIP=$(which gzip); # Set GZIP and run backup
- ${dbpath}/mysqldump -u ${dbuser} -p${dbpass} ${dbopts} | $GZIP -9 > ${flname};
- cd ${curdir};
- fi
- } # end function nysql_bup
- function confg_bup () {
- # Backup the config files
- echo "Backing up the CONFIG file!";
- bkcpth='/3T/backups/LAMP/Config/'; # Declare the def backup path
- apapth='/3T/backups/LAMP/Config/apache2'; # Declare apache2 backup path
- phppth='/3T/backups/LAMP/Config/php'; # Declare PHP backup path
- pmapth='/3T/backups/LAMP/Config/phpmyadmin'; # Declare PHPmyAdmin path
- myspth='/3T/backups/LAMP/Config/mysql'; # Declare mysql backup path
- pgapth='/3T/backups/LAMP/Config/postgres'; # Declare PostGres backup path
- mkdir -p ${bkcpth}; # Create the def backup path
- mkdir -p ${apapth}; # Create apache backup path
- mkdir -p ${phppth}; # Create php backup path
- mkdir -p ${pmapth}; # Create pma backup path
- mkdir -p ${myspth}; # Create mysql backup path
- mkdir -p ${pgapth}; # Create PostGres backup path
- cp '/etc/fstab' "${bkcpth}fstab"; # Copy FSTAB for drive defs
- cp -rf "/etc/apache2/" "${apapth}"; # Copy the Apache Configs
- cp -rf "/etc/php/" "${phppth}"; # Copy the PHP Configs
- cp -rf "/etc/phpmyadmin/" "${pmapth}"; # Copy the PHPmyADMIN Configs
- cp -rf "/etc/mysql/" "${myspth}"; # Copy the MySQL Configs
- cp -rf "/etc/mysql/" "${pgapth}"; # Copy the PostGres Configs
- # Pipe the "Show" result to a file and show with NANO
- resfil='/3T/Syncs/Files/configs_dump.txt'
- ls -al ${bkcpth} > ${resfil}; # Save the Def Configs
- ls -al ${apapth} >> ${resfil}; # Save the Apache Configs
- ls -al ${phppth} >> ${resfil}; # Save the PHP Configs
- ls -al ${pmapth} >> ${resfil}; # Save the PHPmyAdmin Configs
- ls -al ${myspth} >> ${resfil}; # Save the MySQL Configs
- ls -al ${pgapth} >> ${resfil}; # Save the PostGres Configs
- nano ${resfil}; # Show the Resilts File
- } # end function confg_bup
- function prgap_prg () {
- # Remove Apache
- echo "Purging Apache2!";
- # service apache2 stop;
- # or
- pkill apache2;
- apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
- apt remove apache2.*
- apt-get autoremove
- whereis apache2
- rm -rf /etc/apache2
- } # end function prgap_prg
- function prgph_prg () {
- # Remove PHP
- echo "Purging PHP!";
- apt-get purge `dpkg -l | grep php7.2 | awk '{print $2}' | tr "\n" " "`
- apt-get purge php7.*
- apt-get autoremove --purge
- whereis php
- rm -rf /etc/php
- } # end function prgph_prg
- function prgdb_prg () {
- # Remove MYSql
- echo "Purging MYSql!";
- # service mysql stop;
- # or
- pkill mysql;
- apt-get remove --purge *mysql\*
- apt-get remove --purge mysql-server mysql-client mysql-common -y
- #rm -rf /etc/mysql
- apt-get autoremove && apt-get autoclean
- } # end function prgdb_prg
- function prgpg_prg () {
- # Remove PostGres
- echo "Purging PostGres!";
- # service postgres stop;
- # or
- pkill postgres;
- apt-get --purge remove postgresql
- apt-get purge postgresql*
- apt-get --purge remove postgresql postgresql-doc postgresql-common
- # The following lines should be a "do while" loop
- # while pkg in ??
- # apt-get --purge remove ${pkg}
- # > dpkg -l | grep postgres
- # Get the right var above before inacting the remain commands
- # rm -rf /var/lib/postgresql/
- # rm -rf /var/log/postgresql/
- # rm -rf /etc/postgresql/
- # apt-get autoremove && apt-get autoclean
- } # end function prgpg_prg
- function ilamp_ins () {
- # Install LAMP
- echo "Re-Installing LAMP!";
- # There are conflicts in the "apt-get install" command line, which must
- # be resolved before inacting it. Notice it is covering: 1.) CURL,
- # 2.) MariaDB, 2.) MS-SQL, 4.) MongoDB, 5.) MySQL, 6.) MySQL Workbench,
- # 7.) PHP, 8) PHPmyAmin, 8.) PostGres, 10.) PGAdmin, 11.) SQLite,
- # 12.) Sybase.
- # These should be broken out and addressed individually. Probably as
- # individual functions.
- # Any conflicts between the "tasksel" and the "apt-get install" must be
- # found and corrected before execution.
- tasksel install lamp-server;
- mysql_upgrade;
- apt-get install -y mssql-server apache2 curl mysql-server mysql-client
- mysql-common mysql-workbench php phpmyadmin libapache2-mod-auth-mysql
- libapache2-mod-php php-mysql php-cli jam g++ gcc make libpam0g-dev
- libkrb5-dev pax ccache gcc-multilib g++-multilib flex suversion mongodb
- mongodb-client mongodb-server pg-backup-ctl pg-cloudconfig
- pg-rage-terminator-10 pgbackrest pgcharts pgcli pgdbf pgmodeler
- pgmodeler-common pgqd pgadmin4 pgadmin4-apache2 pgxnclient php-curl
- php-json php-cgi mariadb-server mariadb-client net-tools openssh-server
- tasksel sqlite3 sqlitebrowser libsqlite3-dev sybase
- mysql_upgrade;
- } # end function ilamp_ins
- function ipgdb_ins () {
- # Install PostGres
- echo "Installing PostGres!";
- # See Notes from the function above
- } # end function ipgdb_ins
- res=mysql_bup;
- res=confg_bup;
- #res=prgap_prg;
- #res=prgph_prg;
- #res=prgdb_prg;
- #res=prgpg_prg;
- #res=ilamp_ins;
- #res=ipgdb_ins;
- #reboot;
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement