Hello all! What I would like this script to do:
1) check how many backups have been made
2) delete the oldest to make room for the latest
I'm somewhat new to scripting and have some of the script pieced together via snippets of other scripts and addins written by myself. (lots of trial and error!)
This is what I have so far.
SCRIPT
Code:
#!/bin/sh
# ----------------------------------------------------------- #
# 1 - START LOG FILE #
# 2 - Create list of installed software #
# 3 - Sources #
# 4 - Destination #
# 5 - Archive naming #
# 6 - Create actual backup #
# 7 - Copy backup to NAS #
# 8 - Delete local backup #
# 9 - END LOG FILE #
# ------------------------------------------------------------ #
# 1
echo "-------------------------------------------------------------" >> /media/nas/backups/supertux/incremental/backup_LOG.txt
echo "START - `date`" >> /media/nas/backups/supertux/incremental/backup_LOG.txt
# 2
dpkg --get-selections > /home/supertux/Documents/scripts/sync/installed-software.txt
# 3
backup_files="/bin/backup.sh /etc/fstab /home/supertux/Documents /home/supertux/Pictures"
# 4
dest="/"
# 5
day=$(date +%Y%m%d)
archive_file="bu_$day.tar.bz2"
# 6
tar cjf $dest/$archive_file $backup_files
# 7
cp /$archive_file /media/nas/backups/supertux/incremental
# 8
rm /$archive_file
# 9
echo "END - `date`" >> /media/nas/backups/supertux/incremental/backup_LOG.txt
echo "-------------------------------------------------------------" >> /media/nas/backups/supertux/incremental/backup_LOG.txt
# NOTES
# Under line 5 paste *hostname=$(hostname -s)* to prepend current hostname to filename (without * )
#
#
#
#
#
#
# TODO
# Have script check how many backups are there. Keep only 5..maybe 6 or 7 then
# remove the oldest to make room for newest.
# sudo make breakfast
#
#
LOG (which will be fancier as time goes on and I learn more)
Code:
-------------------------------------------------------------
START - Fri May 27 22:23:47 EDT 2011
END - Fri May 27 22:23:48 EDT 2011
-------------------------------------------------------------
-------------------------------------------------------------
START - Sat May 28 00:00:01 EDT 2011
END - Sat May 28 00:00:14 EDT 2011
-------------------------------------------------------------
-------------------------------------------------------------
START - Sun May 29 00:00:01 EDT 2011
END - Sun May 29 00:00:14 EDT 2011
-------------------------------------------------------------
-------------------------------------------------------------
START - Mon May 30 00:00:01 EDT 2011
END - Mon May 30 00:00:13 EDT 2011
-------------------------------------------------------------
-------------------------------------------------------------
START - Tue May 31 00:00:01 EDT 2011
END - Tue May 31 00:00:14 EDT 2011
-------------------------------------------------------------
I'm trying my best to be as neat as possible with my code writing. I've seen some of the codes we use at work and......well I just don't see how anyone else can
interpret them aside from the author. Which was probably purposely done. Any help is greatly appreciated so thanks in advance and hope everyone had a great weekend!!
-Snickasaurus