LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Best way to backup live lampp server (https://www.linuxquestions.org/questions/linux-server-73/best-way-to-backup-live-lampp-server-4175694819/)

linuxpc4me 05-06-2021 05:18 PM

Best way to backup live lampp server
 
Hello!
I have a apache2 / php7.4 / mysql sever on ubuntu 20.04. To prevent me from rebuilding the whole thing again, what is the best way to do a complete nightly backup that can be restored easily? Will I need to do a mysqldump and shut down mysql, then backup, or is there something I can use that will not require this? I heard of TimeShift, Bacula, Rsync, Amanda, etc. I do not want to do a file backup (like dropbox or onedrive) I need a complete backup to restore a production server as simply and quickly as possible.
I even thought of replicating the mysql databases on another machine, and doing multiple sql dumps that would be rsync'd to another machine as well in addition to creating a complete backup of the drive
Thanks for any input

frankbell 05-06-2021 08:25 PM

If you have phpmyadmin installed, it provides backup capability, both for databases and for all files on the site.

In my experience, you can can export your mysql database without shutting dowm mysql. A web search for "phpmyadmin backup" will turn up numerous articles and tutorials.

When to back up and how often are more intriguing questions. If the files other than the database change seldom, then there may not be need to back up the non-database files as frequently as the database itself.

Many years ago, when I self-hosted my site in my early Linux days (that's how I got into Linux--to self-host my website), I wrote a script to back up my databases every night and ran it as a cron job. For what it's worth, I'd do several things differently today, but here's my old script, in case it gives you a starting point:

Code:

#!/bin/bash

#Set the variable NOW

NOW=1

#Define now as today's day-month-year-hour-minute.

NOW=$(date +%m-%d-%Y-%H-%M)

#Make the directory to hold the backup file.

mkdir /root/backups/sql/$NOW

echo "Making the directory for the backup."

cd /opt/lampp/bin

echo "Entering the Lampp directory."

mysqldump -S /opt/lampp/var/mysql/mysql.sock -u [username] -p[password] [databasename] > /root/backups/sql/$NOW/[filename].sql

echo "Backing up database."

cd

echo "Returning to root directory and exiting."


linuxpc4me 05-06-2021 10:38 PM

Frank,

Thank you for the response. I have used several sql queries to backup my DB's. Yours is very nice. The greater part of hte question is: What is the most simplistic but solid way to backup the whole server (hard drive) to ensure the site ( /var/www/html) as well as the complete OS can be restored (like clonezilla)?
This full 'bare-metal-backup' (excluding /home dir) would allow me to recover to a replacement HD / server/ etc in the event of catastrophic loss.

Again, thanks for the wonderful information!


All times are GMT -5. The time now is 05:23 PM.