Community
OpenEnergyMonitor

Community

Automatic backup script with upload to ftp site

Tags: #<Tag:0x00007f15ceca9258> #<Tag:0x00007f15ceca9190> #<Tag:0x00007f15ceca90c8> #<Tag:0x00007f15ceca9000> #<Tag:0x00007f15ceca8f38>

I just created a scrip to create and then upload a backup to a ftp server
1: create folder “arhiva” into /home/pi/data
2: add some files named emoncms-backup-whatevertexthere
the scipt will keep the same number of files and just delete the oldest ones
3: apt-get update, then apt-get lftp
4: sudo crontab-e and add a cron line like this:
0 6 * * * /home/pi/backup-ftp.sh >> /home/pi/backup-ftp.log

DATA=`date +%F`
#echo $DATA
echo Start program $DATA
echo arhivam
cd /home/pi/backup/
bash emoncms-export.sh
cd /home/pi/data/arhiva/ 
#echo rm `head -1 list` 
ls -1 -t -r emoncms-backup* > list 
echo rm `head -1 list` 
rm `head -1 list`
#rm list
echo gata-arhiva

lftp -c "set ftp:list-options -a;
set ssl:verify-certificate false;
open ftp://user:[email protected]; 
lcd /home/pi/data/arhiva/;
mirror --reverse --delete --use-cache --verbose --allow-chown --allow-suid --no-umask --parallel=2 --exclude-glob .svn"

Edit - formatted code for readability. BT - Moderator

1 Like

Thanks for sharing @4est!

adding the script to /etc/cron.daily did not work for some reason
I edited the post with the new solution, to just add it to default crontab.

I will post after 1 week a screenshot of the backup files
This way, even if emoncms sdcard dies (happened to me), you will just have to restore the backup and lose only a few hours of data (max 24h)