public:radio:2024:yaddnet_data_backup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
public:radio:2024:yaddnet_data_backup [19/04/24 09:42 BST] – [Backup UDP receive and logrotate] john | public:radio:2024:yaddnet_data_backup [06/03/25 06:49 GMT] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
- | ====== | + | ====== |
** Offsite Text file backups of all DSC messages ** | ** Offsite Text file backups of all DSC messages ** | ||
- | ===== YaDDNet UDP Mirror ===== | + | * Alan Spindel initially suggested an offsite backup of the DSC messages in 2019 |
+ | * YaDDNet | ||
+ | * The DSC messages are sent by UDP as simple plain text, for easy archiving | ||
+ | * The archived text file can be used if necessary to rebuild the SQL database table containing the DSC messages in case of disaster | ||
+ | * Since I'm now hosting YaDDNet again I decided I should run a UDP log receiver at home to improve the backup provision | ||
+ | * The daily archive files will be '' | ||
+ | * I could share the link to anyone who is interested in using the saved data | ||
+ | ===== YaDDNet UDP Send to Mirror ===== | ||
+ | |||
+ | * In the '' | ||
+ | * This involves converting MMSI -> Coast or Ship name, finding the '' | ||
+ | * Prior to using the newly created message to inject new data into the SQL server '' | ||
+ | * '' | ||
+ | * Any addressed & listening UDP clients receive the UDP packets and append them to a log file | ||
<code python> | <code python> | ||
Line 23: | Line 36: | ||
</ | </ | ||
===== Backup UDP receive and logrotate ===== | ===== Backup UDP receive and logrotate ===== | ||
+ | |||
+ | |||
+ | ==== UDP Listener ==== | ||
<code python> | <code python> | ||
# | # | ||
+ | # | ||
+ | # udp_logger.py | ||
+ | # | ||
import SocketServer | import SocketServer | ||
import socket | import socket | ||
import threading | import threading | ||
- | import re | ||
- | import time | ||
- | |||
- | |||
- | | ||
- | | ||
class ThreadedUDPRequestHandler(SocketServer.BaseRequestHandler): | class ThreadedUDPRequestHandler(SocketServer.BaseRequestHandler): | ||
- | |||
def handle(self): | def handle(self): | ||
data = self.request[0].strip() | data = self.request[0].strip() | ||
Line 46: | Line 58: | ||
self.write_file(data) | self.write_file(data) | ||
- | |||
def write_file(self, | def write_file(self, | ||
filename = '/ | filename = '/ | ||
Line 73: | Line 84: | ||
</ | </ | ||
+ | |||
+ | |||
+ | * The UDP Log Receiver listens to UDP/2505 for incoming packets from YaDDNet. These are of the form: | ||
+ | |||
+ | < | ||
+ | |||
+ | [log]; | ||
+ | [log]; | ||
+ | </ | ||
+ | |||
+ | |||
+ | * each new packet is appended to the running log file ''/ | ||
+ | * the file will grow indefinitely if left to itself! | ||
+ | |||
+ | ==== Logrotate === | ||
+ | |||
+ | * run by Crontab every day at midnight | ||
+ | * copies the current running log to a timestamped file | ||
+ | * erases the contents of the running log file | ||
+ | * '' | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | ## CRONTAB ENTRY | ||
+ | |||
+ | 00 00 * * * / | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | #!/bin/bash | ||
+ | # | ||
+ | # yaddlog_rotate.sh | ||
+ | |||
+ | DROPBOX=/ | ||
+ | DIR=/ | ||
+ | |||
+ | INFILE=yaddnet_udp_log.txt | ||
+ | |||
+ | TIMESTAMP=`date +%Y%m%d_%H%M` | ||
+ | |||
+ | OUTFILE=$TIMESTAMP\_$INFILE | ||
+ | |||
+ | cp $DIR/ | ||
+ | cat /dev/null > $DIR/ | ||
+ | |||
+ | |||
+ | gzip $DIR/ | ||
+ | |||
+ | mv $DIR/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | * This creates a '' | ||
+ | |||
+ | === Starting the UDP Listener at boot-up === | ||
+ | |||
+ | * crontab entry to start it as a background job at '' | ||
+ | |||
+ | <code bash> | ||
+ | # | ||
+ | # CRONTAB ENTRY | ||
+ | # | ||
+ | @reboot python / | ||
+ | |||
+ | </ | ||
+ | |||
--- //John Pumford-Green 19/04/24 09:31 BST// | --- //John Pumford-Green 19/04/24 09:31 BST// | ||
+ | |||
+ | Last updated : ~~LASTMOD~~ | ||
===== Further Information ===== | ===== Further Information ===== | ||
+ | [[https:// | ||
- | {{tag>}} | + | {{tag>radio yaddnet}} |
public/radio/2024/yaddnet_data_backup.1713516139.txt.gz · Last modified: 06/03/25 06:49 GMT (external edit)