MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    What is your backup and restore method?

    Scheduled Pinned Locked Moved Troubleshooting
    18 Posts 10 Posters 6.4k Views 15 Watching
    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.
    • swvalentiS Offline
      swvalenti Project Sponsor
      last edited by

      @Snille Can you dumb this down a little bit for me please, trying to use this…I created key and added to github but not sure how to do the rest.

      SnilleS 1 Reply Last reply Reply Quote 0
      • karsten13K Online
        karsten13
        last edited by

        my approach …

        The following script must be executed in the magicmirror folder and creates another script restore.sh. This result script should be saved (on my server it is under git control) and can be executed (again in the magicmirror folder) to restore the old system (or bringing the old config to a new system).

        #!/bin/sh
        
        base="$(cd "$(dirname "$0")" && pwd)"
        
        restore="$base/restore.sh"
        config="${1:-config/config.js}"
        css="css/custom.css"
        modules="modules"
        
        # Tests
        [ -f "$base/$config" ] || (echo "config.js does not exists" && exit 1)
        [ -f "$base/$css" ] || (echo "custom.css does not exists" && exit 1)
        [ -d "$base/$modules" ] || (echo "modules directory does not exists" && exit 1)
        
        
        echo "#!/bin/sh" > $restore
        echo "" >> $restore
        echo "base=\"\$(cd \"\$(dirname \"\$0\")\" && pwd)\"" >> $restore
        
        echo "" >> $restore
        
        echo "mkdir -p \$base/config" >> $restore
        echo "mkdir -p \$base/css" >> $restore
        echo "mkdir -p \$base/modules" >> $restore
        
        echo "" >> $restore
        
        echo "cat > \$base/$config <<\"EOF\"" >> $restore
        cat <$base/$config >> $restore
        echo "EOF" >> $restore
        echo "" >> $restore
        
        echo "cat > \$base/$css <<\"EOF\"" >> $restore
        cat <$base/$css >> $restore
        echo "EOF" >> $restore
        echo "" >> $restore
        
        for dir in $(find "$modules" -maxdepth 1 -mindepth 1 -type d)
        do
          [ -f "$dir/.git/config" ] && mods="$mods $(cat $dir/.git/config | grep 'url = ' | sed 's|.*url = ||g')"
        done
        
        for repo in $mods
        do
          echo "cd \$base/$modules && git clone $repo" >> $restore
        done
        
        echo "" >> $restore
        
        for repo in $mods
        do
          moddir="$modules/$(echo $repo | sed -r 's|.*\/(.*)|\1|g;s|.git||g')"
          [ -f "$base/$moddir/package.json" ] && echo "cd \$base/$moddir && npm install" >> $restore
        done
        
        echo "Created restore script $restore" 
        
        chmod +x $restore
        
        1 Reply Last reply Reply Quote 2
        • swvalentiS Offline
          swvalenti Project Sponsor
          last edited by

          @karsten13 Looks good but same thing I am not grasping how to implement this…sorry

          1 Reply Last reply Reply Quote 0
          • SnilleS Offline
            Snille Module Developer @swvalenti
            last edited by

            @swvalenti Ok… :)
            You need a “server” (a location where you can “wget” files from for this to work.
            I have a specific backup directory on my own webserver, but you can use any server as long as you can wget from it.

            Then the “Toinstall” part is just me having more the one config files in the backup dir.
            Basically I have 2 different install possibility’s “house” and “NUC”.
            So my backup config files are named “config-house.js” and config-NUC.js".
            I enable the one I want to restore.

            “ConfigName” is the actual name of the config file when it’s copied to it’s destination. This is probably always going to be “config.js” for the MM2. :)

            “User” is in what directory the “MagicMirror” is located (when you cloned it).

            “Moddir” is where your modules will be installed (this is probably always going to the same for MM2 as well).

            “DownloadFrom” is where to download your backed up files from.

            Then it’s just two "array"s with the files and folders with the backup files and where to copy them when restoring.
            Files[1] = “file1-to-copy”
            Dirs[1] = “Where/to/copy/file-1”
            And so on…

            Files[3] Is the script I use to set the screen to sleep and wake it up (Using MMM-Remote-Control).
            Files[4] Is the script I use to automatically update the mirror and the modules (manually).

            Files[7-9] It’s the “compliment-files” (used in the compliments module).

            And Files[11] Is the MagicMirror start script I use (for starting the mirror with pm2).

            “Packfile” Is the name of the file to look for when installing moduls. If it’s there, the npm install will be executed when installing the module.

            Last but not least it’s all the git-repos for the modules I use in my mirror.
            These will be cloned in the “Moddir” and installed (with npm if “Packfile” exists").

            That’s about it. :)

            Let me know if you have any more questions. :)

            If you cant find it, make it and share it!
            Modules: MMM-homeassistant-sensors, MMM-Modulebar, MMM-Profilepicture, MMM-Videoplayer

            1 Reply Last reply Reply Quote 0
            • LusbuebL Offline
              Lusbueb
              last edited by

              i use this tool:

              https://www.linux-tips-and-tricks.de/en/backup/

              every night I make a full backup of all 4 Raspi as a TAR file to a NAS on my network. then i shrink and convert the TAR files into an IMG file (read Framps Linux-Tips-and-Tricks).

              so I can always make a new SD card with my Win10 and Win32 Disk Imager.

              B 1 Reply Last reply Reply Quote 2
              • swvalentiS Offline
                swvalenti Project Sponsor
                last edited by

                @Lusbueb I have a Buffalo NAS LS I am trying to backup too but can’t figure out the right path to add to sudo nano /etc/fstab

                LusbuebL 1 Reply Last reply Reply Quote 0
                • B Offline
                  BillyTheKid9588 @Lusbueb
                  last edited by

                  @Lusbueb this looks interesting.

                  Do you stop mm before the back up?

                  LusbuebL 1 Reply Last reply Reply Quote 0
                  • bheplerB Offline
                    bhepler Module Developer
                    last edited by

                    The only information that is unique to my mirror is the module configuration. I just back up the config.js file whenever I make a change to the mirror configuration. If the mirror needs to be rebuilt, I can quickly build a slick Buster installation, SSH into the Pi, run the installation script, drop the backup config.js to the config folder and then do a half-dozen git clone commands.

                    Once the mirror is up & running, I can do the boring maintenance stuff (apt get update && apt get upgrade) and just let it run in the background.

                    1 Reply Last reply Reply Quote 1
                    • LusbuebL Offline
                      Lusbueb @swvalenti
                      last edited by Lusbueb

                      @swvalenti on my Netgeras ReadyNAS i have enabled NFS and SMB and a Share named backup (everyone has full-access)

                      07cc27f0-c849-4a19-9028-df4b36274fbf-image.png

                      i start the raspibackup.sh-Script with this helper-Script named raspiBackupNfsWrapper.sh

                      #!/bin/bash
                      
                      #######################################################################################################################
                      #
                      # 	Sample script which checks whether a nfsserver is available and exports a specific directory
                      # 	and then starts raspiBackup
                      #
                      #######################################################################################################################
                      #
                      #   Copyright # (C) 2017,2018 - framp at linux-tips-and-tricks dot de
                      #
                      #   This program is free software: you can redistribute it and/or modify
                      #   it under the terms of the GNU General Public License as published by
                      #   the Free Software Foundation, either version 3 of the License, or
                      #   (at your option) any later version.
                      #
                      #   This program is distributed in the hope that it will be useful,
                      #   but WITHOUT ANY WARRANTY; without even the implied warranty of
                      #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                      #   GNU General Public License for more details.
                      #
                      #   You should have received a copy of the GNU General Public License
                      #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
                      #
                      #######################################################################################################################
                      
                      NFSSERVER="192.168.192.10"
                      NFSDIRECTORY="/c/backup"
                      MOUNTPOINT="/backup"
                      
                      VERSION="0.0.3"
                      
                      # add pathes if not already set (usually not set in crontab)
                      
                      if [[ -e /bin/grep ]]; then
                         PATHES="/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin"
                         for p in $PATHES; do
                            if ! /bin/grep -E -q "[^:]$p[:$]" <<< $PATH; then
                               [[ -z $PATH ]] && export PATH=$p || export PATH="$p:$PATH"
                            fi
                         done
                      fi
                      
                      function cleanup() {
                      	umount -f $MOUNTPOINT
                      }
                      
                      trap cleanup SIGINT SIGTERM EXIT
                      
                      if ping -c1 -w3 $NFSSERVER &>/dev/null; then
                      	if showmount -e $NFSSERVER | grep -q $NFSDIRECTORY; then
                      		echo "Mouting $NFSSERVER:$NFSDIRECTORY to $MOUNTPOINT"
                      		mount -t nfs -o soft,vers=3 $NFSSERVER:$NFSDIRECTORY $MOUNTPOINT
                      		if (( $? > 0 )); then
                      			echo "Failed to mount $NFSSERVER:$NFSDIRECTORY"
                      			exit 42
                      		fi
                      		raspiBackup7412.sh
                      		rc=$?
                      		if (( $rc > 0 )); then
                      			echo "raspiBackup failed with rc $rc"
                      			exit $rc
                      		fi
                      	else
                      		echo "Server $NFSSERVER does not provide $NFSDIRECTORY"
                      		exit 1
                      	fi
                      else
                      	echo "Server $NFSSERVER not online"
                      	exit 1
                      fi
                      
                      

                      Will this be helpfull for you?

                      Regards Peter

                      1 Reply Last reply Reply Quote 1
                      • LusbuebL Offline
                        Lusbueb @BillyTheKid9588
                        last edited by

                        @BillyTheKid9588 yes, in the raspiBackup.conf i have this to lines to stop an start MM:

                        
                        # commands to stop services before backup separated by &
                        DEFAULT_STOPSERVICES="sudo -u pi pm2 stop mm && systemctl stop lighttpd"
                        
                        # commands to start services after backup separated by &
                        DEFAULT_STARTSERVICES="systemctl start lighttpd && sudo -u pi pm2 start mm"
                        
                        

                        Will this be helpfull for you?

                        Regards Peter

                        1 Reply Last reply Reply Quote 1
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Sam, technical setup by Karsten.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy