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."