Xentrk
Part of the Furniture
The post would be easier to read if you put the code examples in CODE blocks.Presentation of my backup concept:
Conditions:
1. daily backup of the jffs
2. daily backup of the usb-device (sda1-Entware Repository)
3. daily backup of the cfg using nsru, rotation 7 days
Solutions:
1. daily backup of the jffs with rsync on usb-device (sda1)
################################################################
script:
################################################################
#!/bin/sh
#
logger -t $(basename $0) "jffs_bak start [$@]"
#
# copy the data
rsync -av --delete /jffs/ /tmp/mnt/sda1/jffs_bak/
#
logger -t $(basename $0) "jffs_bak finish [$@]"
################################################################
2. daily backup of the usb device (sda1) as a tar file on a CIFS-mounted NAS or ssd device
################################################################
script:
################################################################ #!/bin/sh
#
# SOURCEDIR is the path to Entware installation place
SOURCEDIR=/tmp/mnt/sda1
# OUTPUTDIR is the path where backups should be created
OUTPUTDIR=/cifs1/sda1_hell04/
# NUMBERBCKS means how much old copies of backup should be left
# NUMBERBCKS=0 means backup will be overwritten every time and no old copy will be left
NUMBERBCKS=0
EXCLUDE=/tmp/mnt/sda1/exclude.txt
if [ -f ${OUTPUTDIR}/sda1.tar.gz.bck${NUMBERBCKS} ];
then
rm -f ${OUTPUTDIR}/sda1.tar.gz.bck${NUMBERBCKS}
fi
count=$(($NUMBERBCKS-1))
while [ $count -gt 0 ]
do
if [ -f ${OUTPUTDIR}/sda1.tar.gz.bck${count} ];
then
mv ${OUTPUTDIR}/sda1.tar.gz.bck${count} ${OUTPUTDIR}/sda1.tar.gz.bck$(($count+1))
fi
count=$(($count-1))
done
if [ -f ${OUTPUTDIR}/sda1.tar.gz ] && [ $NUMBERBCKS -ne 0 ];
then
mv ${OUTPUTDIR}/sda1.tar.gz ${OUTPUTDIR}/sda1.tar.gz.bck1
fi
tar -cf ${OUTPUTDIR}/sda1.tar.gz -X /tmp/mnt/sda1/exclude.txt -C ${SOURCEDIR} .
################################################################
script with swp-file:
################################################################
#!/bin/sh
#
# SOURCEDIR is the path to Entware installation place
SOURCEDIR=/tmp/mnt/sda1
# OUTPUTDIR is the path where backups should be created
OUTPUTDIR=/cifs1/sda1_hell04/
# NUMBERBCKS means how much old copies of backup should be left
# NUMBERBCKS=0 means backup will be overwritten every time and no old copy will be left
NUMBERBCKS=0
if [ -f ${OUTPUTDIR}/sda1swp.tar.gz.bck${NUMBERBCKS} ];
then
rm -f ${OUTPUTDIR}/sda1swp.tar.gz.bck${NUMBERBCKS}
fi
count=$(($NUMBERBCKS-1))
while [ $count -gt 0 ]
do
if [ -f ${OUTPUTDIR}/sda1swp.tar.gz.bck${count} ];
then
mv ${OUTPUTDIR}/sda1swp.tar.gz.bck${count} ${OUTPUTDIR}/sda1swp.tar.gz.bck$(($count+1))
fi
count=$(($count-1))
done
if [ -f ${OUTPUTDIR}/sda1swp.tar.gz ] && [ $NUMBERBCKS -ne 0 ];
then
mv ${OUTPUTDIR}/sda1swp.tar.gz ${OUTPUTDIR}/sda1.tar.gz.bck1
fi
tar -cf ${OUTPUTDIR}/sda1swp.tar.gz -C ${SOURCEDIR} .
################################################################
3. not available, my problem: rotation max. 7 days in the nsru / backup-directory
better: direct backup as cfg and tar file on CIFS-mounted NAS or ssd device
@ Xentrk: can you help me?
possible problems:
1. USB device could age faster / become defective
Solution: daily jffs backup directly to CIFS-mounted NAS or ssd device
################################################################
sript:
################################################################
#!/bin/sh
#
# SOURCEDIR is the path to Entware installation place
SOURCEDIR=/jffs
# OUTPUTDIR is the path where backups should be created
OUTPUTDIR=/cifs1/jffs_hell04/
# NUMBERBCKS means how much old copies of backup should be left
# NUMBERBCKS=0 means backup will be overwritten every time and no old copy will be left
NUMBERBCKS=7
#EXCLUDE=/tmp/mnt/sda1/exclude.txt
if [ -f ${OUTPUTDIR}/jffs.tar.gz.bck${NUMBERBCKS} ];
then
rm -f ${OUTPUTDIR}/jffs.tar.gz.bck${NUMBERBCKS}
fi
count=$(($NUMBERBCKS-1))
while [ $count -gt 0 ]
do
if [ -f ${OUTPUTDIR}/jffs.tar.gz.bck${count} ];
then
mv ${OUTPUTDIR}/jffs.tar.gz.bck${count} ${OUTPUTDIR}/jffs.tar.gz.bck$(($count+1))
fi
count=$(($count-1))
done
if [ -f ${OUTPUTDIR}/jffs.tar.gz ] && [ $NUMBERBCKS -ne 0 ];
then
mv ${OUTPUTDIR}/jffs.tar.gz ${OUTPUTDIR}/jffs.tar.gz.bck1
fi
tar -cf ${OUTPUTDIR}/jffs.tar.gz -C ${SOURCEDIR} .
################################################################
For item 3, here is an example of using the find command to check if a file is older than seven days. If so, take some action.
Code:
if [ "$(find "$DIR" -name "$IPSET_NAME" -mtime +7 -print)" = "$DIR/$IPSET_NAME" ]; then
Download_AMAZON "$IPSET_NAME" "$REGION"
fi