NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public NextPVR Support Linux v
« Previous 1 … 3 4 5 6 7 … 34 Next »
Remote NextPVR backup script for Linux

 
  • 0 Vote(s) - 0 Average
Remote NextPVR backup script for Linux
snagglewest
Offline

Senior Member

VA USA
Posts: 361
Threads: 60
Joined: Jul 2011
#1
2024-02-05, 07:04 PM (This post was last modified: 2024-02-06, 09:53 PM by snagglewest.)
Figured I'd share this script in case someone might find it useful. I recently lost my NextPVR setup. I'll spare the gory details but after spending an evening rebuilding NextPVR I swore I'd never go thru that pain again. 

The script creates a zip of all the files needed to restore NextPVR to a new system and copies the file to a NAS mount. I'm not a coder but it works, YMMV.  You'll need to change any paths to fit your use case and run daily from a cron job to fully automate it.

The script creates a zip file containing copies of the /var/opt/nextpvr/ directory to include the npvr.db3, user defined channel icons, user defined scripts, config.xml and any .xml files such as extra files.  It also backs up any .m3u in /home/npvr/ directory.  Once the zip is created locally it's moved a mount point on my NAS. (/backups/NextPVR/ in this case)

In short the script does 6 steps:

# 1. Creates local zip named "YYYY-MM-DD_NPVR_backup"
# 2. Copies the local zip to the NAS mount
# 3. Deletes the local copy of the zip
# 4. Deletes any backups older than 30 days
# 5. Checks the log file and rotates it if needed
# 6. Deletes any logs older than 30 days

The idea is to completely automate it and not require any monitoring.
Code:
#! /usr/bin/bash
# script to zip the data files for NextPVR and move it to a share on a NAS
# the script is designed to require minimal monitoring and performs 6 steps:
# 1. Creates local zip named "YYYY-MM-DD_NPVR_backup"
# 2. Copies the local zip to the NAS mount
# 3. Deletes the local copy of the zip
# 4. Deletes any backups older than 30 days
# 5. Checks the log file and rotates it if needed
# 6. Deletes any logs older than 30 days
# "npvr" is the system user in this case
# Create a mount on the NAS - this  is mapped to "/mnt/backups/" on the local machine
# run a a a cron job to automate it
echo "root version of script" >> /home/npvr/backup_script.log
echo "backup_script cronjob started  $(date +%FT%T)" >> /home/npvr/backup_script.log
cd /
zip -v -r "$(date +"%Y-%m-%d")_NPVR_backup.zip" /var/opt/nextpvr/media/channels 2>&1 >> /home/npvr/backup_script.log
zip -v -u "$(date +"%Y-%m-%d")_NPVR_backup.zip" /home/npvr/*.m3u 2>&1 >> /home/npvr/backup_script.log
zip -v -u "$(date +"%Y-%m-%d")_NPVR_backup.zip" /var/opt/nextpvr/npvr.db3 2>&1 >> /home/npvr/backup_script.log
zip -v -u "$(date +"%Y-%m-%d")_NPVR_backup.zip" /var/opt/nextpvr/*.xml 2>&1 >> /home/npvr/backup_script.log
zip -v -u "$(date +"%Y-%m-%d")_NPVR_backup.zip" /var/opt/nextpvr/scripts/*.sh 2>&1 >> /home/npvr/backup_script.log
# copy the local zip file to the NAS mount location
scp "$(date +"%Y-%m-%d")_NPVR_backup.zip" /mnt/backups 2>&1 >> /home/npvr/backup_script.log
# remove local zip file
rm "$(date +"%Y-%m-%d")_NPVR_backup.zip" 2>&1 >> /home/npvr/backup_script.log
# delete-backups older than 30 days
find /mnt/backups/ -type f -name "??-??-????_NPVR_backup.zip" -mtime +30 -exec rm -rf {} \;
echo "backup_script cronjob completed$  $(date +%FT%T)" >> /home/npvr/backup_script.log
echo "=====================================================" >> /home/npvr/backup_script.log
# scripting to rotate logs
echo "=== starting log check and rotate ====" >> /home/npvr/backup_script.log
f="/home/npvr/backup_script.log"
touch ${f}
MAXSIZE=$((4096*256))
size=`du -b ${f} | tr -s '\t' ' ' | cut -d' ' -f1`
if [ ${size} -gt ${MAXSIZE} ]
then
    echo "Rotating!"  >> /home/npvr/backup_script.log
    timestamp=`date +%s`
    mv ${f} ${f}.$timestamp
    touch ${f}
fi
# delete logs older than 30 days
find /home/npvr/ -type f -name "backup_script.log.*" -mtime +30 -exec rm -rf {} \;
echo "log rotate script complete"  >> /home/npvr/backup_script.log
echo "=====================================================" >> /home/npvr/backup_script.log
NextPVR V6.1.5.231022 - Ubuntu 22.04 VM / 4 core / 8Gb memory
HDHR Prime X2 / HDFX-2 /Schedule Direct / 2X Pi4 + & 3X Pi3 LibreELEC Kodi clients
Server - TrueNAS/ SuperMicro MBD-X10SL7-F MB / Xeon E3-1246 / 32Gb Unbuffered ECC / 8 X 4TB RAIDZ2
gEd
Offline

Posting Freak

London
Posts: 3,514
Threads: 100
Joined: Jan 2005
#2
2024-02-05, 10:18 PM
nice. The script even does it's own housekeeping!

At the risk of sounding pedantic, if it were my script, I'd check if scp succeeds before removing the local backup file in case the destination mount point was unavailable or there is a problem with permissions.

Also, I believe that this bit of code is superfluous as the first line (echo "root version of script" >> /home/npvr/backup_script.log) will ensure that the log file always exists.

if [ ! -f $f ]
then
echo "$f does not exist!" >> /home/npvr/backup_script.log
exit
fi
touch ${f}

It's also important to have at least one of these backups stored in the cloud somewhere (to complete the 3-2-1 backup rule).

thanks for sharing.
“If this is the way Queen Victoria treats her prisoners, she doesn't deserve to have any.”
snagglewest
Offline

Senior Member

VA USA
Posts: 361
Threads: 60
Joined: Jul 2011
#3
2024-02-06, 05:44 PM
Thanks for the ideas. It's V1.0 so it can always use some tweaks for sure.
NextPVR V6.1.5.231022 - Ubuntu 22.04 VM / 4 core / 8Gb memory
HDHR Prime X2 / HDFX-2 /Schedule Direct / 2X Pi4 + & 3X Pi3 LibreELEC Kodi clients
Server - TrueNAS/ SuperMicro MBD-X10SL7-F MB / Xeon E3-1246 / 32Gb Unbuffered ECC / 8 X 4TB RAIDZ2
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Linux Command Line To Initiate SchedulesDirect EPG Update LinuxDVR 1 232 2025-04-13, 06:35 PM
Last Post: mvallevand
  NextPVR can't open RAI (Italian main TV channels) links f2fg 17 3,163 2025-03-29, 10:15 AM
Last Post: alice_anto
  Linux install failed -- permission denied? FrogFan 4 517 2025-03-26, 12:39 AM
Last Post: FrogFan
  Guide data issue using NextPVR in a Proxmox LXC njc 10 940 2025-03-23, 01:40 PM
Last Post: njc
  NextPVR oddly limited to 7 tuners DaVinylSmith 4 491 2025-02-12, 02:49 PM
Last Post: DaVinylSmith
  NextPVR webserver not starting, prevents client from starting homemaisonbaile 28 1,345 2025-02-04, 05:23 PM
Last Post: mvallevand
  Is there a 'recommended' version/release of Linux? Bobthegoldfish 1 397 2024-12-24, 12:28 AM
Last Post: mvallevand
  NextPVR 7 looses recordings after post processing ballfam 15 904 2024-12-20, 03:23 AM
Last Post: ballfam
  Colossus 2 and nextpvr Iriman 53 4,795 2024-12-16, 02:32 AM
Last Post: ehfortin
  NextPVR user1232 1 316 2024-11-09, 11:21 AM
Last Post: mvallevand

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode