Autobackup

Hi, please,

I had almost lost my all backups on a corrupted microSD so not any backup would have been useful a few days ago :slight_smile: Fortunately I had a backup on my notebook.

So would be super useful to have a possibility to:

  1. set auto backup

  2. set a location of the backups
    (*not so important

  3. an option to exclude thumbnails (or make 2 backups optionally)

  4. an option to create also a Kodi backup (independent from the operating system for an easier migration across platforms, so maximally 3 kinds of backup, 3 files)
    )

  5. a button “create the backups right now” of course too :slight_smile:

  6. and have NO worry about anything wrong that could happen any time :slight_smile:

What do you think?

edit: not talking about Kodi but about the whole CoreElec as is done by the CE settings of course :slight_smile:
added just Kodi backup possibility

2 Likes

That would be a great and very useful feature :slight_smile:

1 Like

It looks like there could be an existing kodi addon to do this:-

I haven’t tried it myself but it looks as though it does what you are looking for. You can specify the backup location, select which file types to backup and run the backup on a schedule.

I dont know how to skip the thumbnails, but i have a backup solution. I run the following command and a backup is created:

tar cpf /your/path/here/$(date +%Y%m%d%H%M%S).tar /storage

You could have this command run everyday automatically at 4:00 am by adding this line to cron:

0 4 * * * tar cpf /your/path/here/$(date +%Y%m%d%H%M%S).tar /storage

Though, this will accumulate backups over time. Maybe someone with better linux knowledge can tell you of a command that will delete old backups.

1 Like

Is this “Backup” add-on working exactly as the CoreElec backup ?
It’s been years since the last time I’ve used it, but I do remember abandoning it because restoring from a backup never worked reliably for me.
CoreElec backup, on the other hand seems to work perfectly.

1 Like

but maybe the possible settings could take into account even a creation also a Kodi settings to make a migration to a completely different system easier, so two files could be created acc to the user :slight_smile:

I might give it a go later and report my findings.

From memory , I think you have to force close Kodi when the restore backup is at the end.
I Haven’t used it with CE but that is what i do on Android.

Thanks for the feedback.
I think it’s time to try again that Backup add-on.
I will also keep a CoreElec backup to be on the safe side, before I try with the add-on.

I have seen a big demand about this so here is the full Cron+script automatied solution in my case with (arbitrarily):

  • excluded thumbnails (you can disable it of course in the script)
  • every 3rd day at 3:00 AM
  • saved on USB flash
  • keeps 50 backups in total

It’s done in 2 seconds because of the excluded thumbnails in this case (around 80MB).

  1. create script backup.sh for backup and save the file to /storage/.kodi/userdata/backup.sh
#!/bin/bash
#Purpose = Backup Kodi
#save this file to /storage/.kodi/userdata/backup.sh
#define your backup-directory

DESTDIR="/var/media/8 GB/kodi_backup/"
#DESTDIR=/storage/backup/
cd "$DESTDIR"

#number of backups, which exists after the script will have been finished = NUM+1
#50 backups to be saved
NUM=49
ls -1tr "$DESTDIR"/*.tar | head -n -$NUM | while read -r i
do
  rm "$i"
done

TIME=`date +%Y%m%d%H%M%S` 	# date in backup name.
FILENAME=$TIME.tar 			# Backup Name

SRCDIR="/storage/.kodi/ /storage/.cache /storage/.config/"
SRCDIR_EXCLUDE="--exclude=storage/.kodi/userdata/Thumbnails"

tar cvf "$DESTDIR/$FILENAME" $SRCDIR_EXCLUDE $SRCDIR
  1. enable cron in the CoreElec settings
  2. set task for the every 3rd day at 3:00 AM
    3a) crontab -e
    3b) 00 03 */3 * * /storage/.kodi/userdata/backup.sh
    3c) press ctrl+x
    3d) y
    3e) enter
  3. not sure about a restart, probably not necessary
  4. recommend to delete to recreate thumbnails after backup restore this database: /storage/.kodi/userdata/Database/Textures13.db

Done

Thx to @pepeq and @gregeeh for the script we have started with.
Would be very nice to have this in wiki or even in the backup section GUI.

Hey, I’ve got this script working fine, but for some reason the cron job isn’t running. I’ve set it to run every day at 8pm and the output of crontab -l shows as:

0 0 20 ? * * * /storage/.kodi/userdata/backup.sh

It doesn’t seem to run though, what am I doing wrong? Cron is enabled under coreelec settings.

Lot of thanks for this script
How should be made the import of the backup?

I think now it’s better to just CE commands instead of just copying like in the script.

To use a backup by this script just use a common copy/overwrite command.

But CE commands don’t skip thumbnails, do they?
How do I extract the file created by the script?

CE backup does skip thumbnails. It makes a .tar file which can be decompressed with any decent unpacking program on PC.

1 Like

Hi all,

I have my backup.sh script in /storage/.kodi/userdata/
I added this line to my autostart.sh file
(sleep 20; /storage/.kodi/userdata/backup.sh >& /storage/.kodi/userdata/backup.sh.log)&
but im getting this output in the log file

/storage/.config/autostart.sh: line 35: /storage/.kodi/userdata/backup.sh: not found

any ideas?

I don’t know where you got the error, you will have to look for it yourself and always check that the scripts are executable files.

I give you my automatic backup at six in the morning every three days that deletes backups older than ten days:

/storage/.config/autostart.sh
...
crontab /storage/.config/scripts/crontab.conf
...

/storage/.config/scripts/crontab.conf
...
0 6 */3 * * /storage/.config/scripts/backup-full.sh
15 6 * * * kodi-send -a reboot # reboot every day at 06:15
...

/storage/.config/scripts/backup-full.sh
#!/bin/sh
# full backup
tar cvf /media/5TB-HDD/.Backups/kodi-backup/$(date +%Y%m%d%H%M%S).tar \
–exclude=Thumbnails --exclude=.thumbnails \
/storage/.kodi /storage/.cache /storage/.config
find /media/5TB-HDD/.Backups/kodi-backup -name “*.tar” -type f -mtime +10 -exec rm -f {} ;

Note.-

5TB-HDD is the name of my external drive