Add cron for database backup

This commit is contained in:
2025-08-01 07:01:37 -04:00
parent c40830ef16
commit 3673fa9a4b
2 changed files with 37 additions and 1 deletions

View File

@@ -160,7 +160,7 @@ crontab is...
(minute) (hour) (day of month) (month) (day of week)
The following is the production crontab. you can directly copy these lines into the cron schedule...
The following is the production crontab for DIA. you can directly copy these lines into the cron schedule...
1) Stop the cron service. sudo service cron stop
2) Copy/Paste daya ... sudo crontab -e and then copy the below lines
3) Restart cron sudo service cron restart
@@ -187,3 +187,19 @@ CRON_DIR_IPMONITOR=/opt/MarketData/IPMonitor
0 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor IPMONITOR /FORCE:true > /dev/null 2>&1
10,20,30,40,50 * * * * cd $CRON_DIR_IPMONITOR ; /opt/MarketData/IPMonitor/ipmonitor > /dev/null 2>&1
The following is the production crontab for Adrastea to backup the database every saturday at noon. you can directly copy these lines into the cron schedule...
1) Stop the cron service. sudo service cron stop
2) Copy/Paste daya ... sudo crontab -e and then copy the below lines
3) Restart cron sudo service cron restart
4) Ensure cron is running sudo service cron status
# sudo service cron reload , sudo service cron restart
# cron helper app here -> https://cron.help/#*/5_9-17_*_*_1-5
# m h dom mon dow command
# sudo service cron reload , sudo service cron restart
# cron helper app here -> https://cron.help/#*/5_9-17_*_*_1-5
CRON_DIR=/home/pi/ARM64/Scripts
0 12 * * 6 cd $CRON_DIR ; ./dump.sh > /dev/null 2>&1

20
Scripts/dump.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
TARGET_FILE=backupdb.sql
TAR_FILE=backupdb.tar.gz
printf "Dumping database\n"
if test -f "$TARGET_FILE"
then
echo "Removing $TARGET_FILE"
sudo rm "$TARGET_FILE"
fi
if test -f "$TAR_FILE"
then
echo "Removing $TAR_FILE"
sudo rm "$TAR_FILE"
fi
echo "Creating $TARGET_FILE"
#mysqldump --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --databases market_data portfolio_data user_data --user=root --password=dbas --master-data > "$TARGET_FILE"
mysqldump --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --databases market_data portfolio_data user_data --user=root --password=dbas --master-data | pv > "$TARGET_FILE"
echo "Creating $TAR_FILE"
tar -czvf "$TAR_FILE" "$TARGET_FILE"