• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Script for a backup ?

    Scheduled Pinned Locked Moved
    General Problems
    backup dump rsync
    3
    5
    746
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Bristow 0
      last edited by Bristow 0

      At present, I clone my proxmox virtual machine for my backups and from time to time, I manually run a dump of the database and images.

      I’d like to automate this backup via a cron. Do you have a script that allows me to :

      • database dump
      • rsync images to remote media

      Perhaps you have something better to suggest? Thanks 🙏

      falkoF 1 Reply Last reply Reply Quote 0
      • falkoF
        falko Moderator @Bristow 0
        last edited by

        @Bristow-0 you may already do this. But you mentioned you clone the vm and not back it up. Would it not be best to run a proxmox backup of the fog server VM to another location like a Nas/share located elsewhere.

        B 1 Reply Last reply Reply Quote 0
        • B
          Bristow 0 @falko
          last edited by

          @falko Yes, I already clone my VM on a remote space. But if my clone isn’t correct, I lose everything.
          So I’d like a backup script that allows me to automate a database backup and an rsync to a remote share. You can never be too careful.

          R 1 Reply Last reply Reply Quote 0
          • R
            rodluz Developer @Bristow 0
            last edited by

            @Bristow-0 A while back, I was trying to find an answer to your question, but I couldn’t find anything, so I just wrote it myself. It’s not perfect, but this could be a good starting point.

            I have it set up on a Proxmox LXC container running Ubuntu 22.04 and it’s running on a cron job weekly. If you want to go this route, you just have to set up a few things on the container first.

            • Make sure you can send emails from the container. I use msmtp, but you can use something else that you prefer, just make sure to change the command in the script.
            • Make sure you can SSH into your FOG server from the container with an SSH key so that you don’t have to deal with username/password.
            • Not extremely necessary but recommended. Add a mount point, to the container, of a separate storage location to save all the data to.
              • In the script, I have it set to /mnt/FOGBackups

            Make sure that you read through the script and change the FOG information.

            For some reason the forum doesn’t show the bash script correctly, so I am adding a link to a public gist with the code: https://gist.github.com/rluzuriaga/a2cd00cbff9a5cc70d0fb93afdd15566

            Hope this helps!

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            B 1 Reply Last reply Reply Quote 0
            • B
              Bristow 0 @rodluz
              last edited by Bristow 0

              Thanks a lot @rodluz !

              I took your script and adapted it. I use it directly on my FOG server, which simplifies things a bit. I also changed the mail to a notification sent to my smartphone with ntfy, which I find easy to use.

              I also mounted my NAS share in NFS directly on /mnt/FOGBackups.

              Here’s my script:

              #!/bin/bash
              
              fogServerAddress="172.X.Y.Z"  # Change to actual FOG server address
              
              backupDate=$(date +"%Y%m%d")
              
              backupDir="/mnt/FOGBackups/$backupDate"
              backupDirImages="/mnt/FOGBackups/images"
              
              snapinLocation="/opt/fog/snapins"
              reportLocation="/var/www/fog/lib/reports"
              imageLocation="/images"
              
              failedBackupDB=0
              failedBackupSnapins=0
              failedBackupReports=0
              failedBackupImages=0
              
              [[ ! -d $backupDir ]] && mkdir -p $backupDir/{mysql,snapins,reports,logs} >/dev/null 2>&1
              [[ ! -d $backupDir/mysql || $backupDir/snapins || $backupDir/reports || $backupDir/logs ]] && mkdir -p $backupDir/{mysql,snapins,reports,logs} >/dev/null 2>&1
              
              backupDB() {
                  wget --no-check-certificate --post-data="nojson=1" -O $backupDir/mysql/fog.sql "http://$fogServerAddress/fog/management/export.php?type=sql" 2>>$backupDir/logs/error.log 1>>$backupDir/logs/progress.log 2>&1
                  stat=$?
                  if [[ ! $stat -eq 0 ]]; then
                      echo "Failed to backup database!"
                      failedBackupDB=1
                  else
                      echo "Database backed up."
                  fi
              }
              
              backupSnapins() {
                  cp -r $snapinLocation $backupDir/snapins/ 2>>$backupDir/logs/error.log 1>>$backupDir/logs/progress.log 2>&1
                  stat=$?
                  if [[ ! $stat -eq 0 ]]; then
                      echo "Failed to backup snapins!"
                      failedBackupSnapins=1
                  else
                      echo "Snapins backed up."
                  fi
              }
              
              backupReports() {
                  cp -r $reportLocation $backupDir/reports/ 2>>$backupDir/logs/error.log 1>>$backupDir/logs/progress.log 2>&1
                  stat=$?
                  if [[ ! $stat -eq 0 ]]; then
                      echo "Failed to backup reports!"
                      failedBackupReports=1
                  else
                      echo "Reports backed up."
                  fi
              }
              
              backupImages() {
                  rsync -auv $imageLocation $backupDirImages 2>>$backupDir/logs/error.log 1>>$backupDir/logs/progress.log 2>&1
                  stat=$?
                  if [[ ! $stat -eq 0 ]]; then
                      echo "Failed to backup images!"
                      failedBackupImages=1
                  else
                      echo "Images backed up."
                  fi
              }
              
              checkForFailures() {
                  echo "Running checkForFailures()"
                  if [[ $failedBackupDB -eq 1 ]]; then
                      message="$message \nFailed to backup database."
                  fi
              
                  if [[ $failedBackupSnapins -eq 1 ]]; then
                      message="$message \nFailed to backup snapins."
                  fi
              
                  if [[ $failedBackupReports -eq 1 ]]; then
                      message="$message \nFailed to backup reports."
                  fi
                  if [[ $failedBackupImages -eq 1 ]]; then
                      message="$message \nFailed to backup images."
                  fi
              }
              
              sendNotif() {
              	echo "Running sendNotif()"
                  if [[ ! -z $message ]]; then
                      {
                          curl -d "FOG Backup Failed\n $message" ntfy.sh/XYZATEHFJICH
              		}
              	else
              		curl -d "FOG Backup Successful!" ntfy.sh/XYZATEHFJICH
              	fi
              }
              
              backupDB
              backupSnapins
              backupReports
              backupImages
              
              checkForFailures
              sendNotif
              
              
              1 Reply Last reply Reply Quote 2
              • 1 / 1
              • First post
                Last post

              155

              Online

              12.0k

              Users

              17.3k

              Topics

              155.2k

              Posts
              Copyright © 2012-2024 FOG Project