v1 Backup - jzohrab/lute GitHub Wiki
This documentation is deprecated/obsolete. Lute v2 has been replaced by Lute v3, a full Python rewrite. Please see the Lute v3 manual which includes notes on installation. If you have Lute v2, you can easily migrate to v3. Thank you!
If you were using a paid service like LingQ, they'd have a backup plan in place so you wouldn't lose any data in case of technical problems. You should do the same!
There are a few options:
- Use Lute's built-in backup feature.
- Run your own backup scripts, or use mysqldump or phpadmin or whatever
- Create your own cron job, etc.
As a techie, I feel that creating your own cron (scheduled) job is best, but if that's too tough then you can use Lute to do it for you.
Lute provides a simple backup facility that creates a database dump file (using mysqldump) and copies all of your term images to a backup folder that you specify. (First iteration of this feature delivered late March 2023, things may change in future releases if needed.)
The keys are specified in your .env.local file. If you already have an .env.local file, you can copy the keys from the .env.local.example file, or from the snippet below:
# Enable automatic (and manual) backup via Lute? (yes/no)
BACKUP_ENABLED=true
# mysqldump command:
BACKUP_MYSQLDUMP_COMMAND=mysqldump
# Where to put backups (folder must exist):
BACKUP_DIR=/full/path/to/your/backup/folder
# Run backups automatically (daily)? (yes/no)
BACKUP_AUTO=yes
# Warn if backup hasn't been run in a week? (yes/no)
BACKUP_WARN=yes
Note: be sure to remove the '#' at the start of each BACKUP_ line to enable the key! :-)
This key is required. Set BACKUP_ENABLED=no if you're handling your own backups with scripts or whatever, and BACKUP_ENABLED=yes if you want to run them through the Lute UI or have Lute do daily backups.
This is probably going to just be BACKUP_MYSQLDUMP_COMMAND=mysqldump, but you may have a different setup for your machine. Try setting it to mysqldump first and see if the backup works.
Examples of this setting for other systems:
| system | setting |
|---|---|
| Mac, regular mysql installation | BACKUP_MYSQLDUMP_COMMAND=mysqldump |
| Mac, MAMP | BACKUP_MYSQLDUMP_COMMAND=/Applications/MAMP/Library/bin/mysqldump |
| Windows, XAMPP | BACKUP_MYSQLDUMP_COMMAND=C:\\xampp\\mysql\\bin\\mysqldump.exe |
Note the double backslash for windows!
This is the existing directory where a gzipped database export, and copy of all of your images, will be sent. Set this to something that is backed up, such as to a DropBox folder or similar. For me on my mac, I have this set to BACKUP_DIR=/Users/jeff/Dropbox/LuteBackup.
If this is set to yes, Lute will run the backup from the Home page every day. Note that this is only from the Home page, so if you have a book open for reading for 2 weeks, it won't be backed up. :-)
If this is set to yes, Lute will print a warning on the Home page if the last backup was run more than one week ago. Again, this is only from the home page.
Once you've set the keys, go to the Lute home page, and click "Create backup". Then check that the file is created correctly in the BACKUP_DIR you specified.
If you don't want Lute to manage your backups (you've set BACKUP_ENABLED=no in your .env.local), you might want to set up your own scheduled job for backups.
Here's my backup script (it probably only works on a mac, but it might give you some ideas). It backs up specified databases to a folder in my dropbox, creating a new datetime-stamped folder for each backup (eg 23-03-27-20-06-1679972769/), and also zips up the images in public/userimages to userimages.tar.gz. Note the complete disregard for security :-/
# file: /Users/jeff/crons/backup-lute/do_backup.sh
#!/bin/bash
set -e
# set -x
# copied and mod'ed from https://gist.github.com/zertrin/5883555
DBUSER="root"
DBPASS="root"
BACKUPROOT="/Users/jeff/Dropbox/LuteCronBackup"
MYSQLBINROOT="/usr/local/bin"
DATEFORMAT=`date +%y-%m-%d-%H-%M-%s`
BACKUPDIR="${BACKUPROOT}/${DATEFORMAT}"
DBS="lute test_lute learning-with-texts"
echo "Cleaning up backup directory..."
find $BACKUPROOT -type d -ctime +7 -exec rm -rf {} +
echo "Cleaning done."
if [ ! -d ${BACKUPDIR} ]; then
echo "Creating backup directory ${BACKUPDIR} ..."
if ! mkdir -p ${BACKUPDIR}; then
echo "Backup directory ${BACKUPDIR} could not be created by this user: ${USER}" 1>&2
echo "Aborting..." 1>&2
exit 1
else
echo "... done."
fi
elif [ ! -w ${BACKUPDIR} ]; then
echo "Backup directory ${BACKUPDIR} is not writeable by this user: ${USER}" 1>&2
echo "Aborting..." 1>&2
exit 1
fi
for DBNAME in $DBS
do
echo "Exporting ${DBNAME} ..."
$MYSQLBINROOT/mysqldump -u $DBUSER -p$DBPASS $DBNAME | gzip > $BACKUPDIR/$DBNAME.sql.gz
echo "... done."
done
echo "Copying images to ${BACKUPROOT} ..."
cp -R /Users/jeff/Public/lute/public/userimages $BACKUPROOT/
echo "done."
# Zipping doesn't do much ... from 13MB to 10MB...
echo "Zipping images..."
pushd $BACKUPROOT
tar -czf userimages.tar.gz userimages/
rm -rf userimages/
popd
echo "done."
echo
echo "Finished backups in ${BACKUPDIR}:"
ls -larth $BACKUPDIR
I then schedule this in my crontab as follows:
$ crontab -l
0 */3 * * * pushd /Users/jeff/crons/backup-lute && ./do_backup.sh && popd >> /tmp/cron.out 2>&1