Improve my back up scripts

I have 3 scripts that I did :slight_smile: and am happy with as they work.
Make backup of moodledata

#/bin/sh
cp -R /srv/www/moodledata /backups/moodledatacopied/
tar -czvf /backups/moodledata/moodledata.tar.gz /backups/moodledatacopied/
mkdir -p /backups/moodledata/moodledata/`/bin/date +%Y/%b`
/bin/mv /backups/moodledata/moodledata.tar.gz /backups/moodledata/moodledata/`/bin/date +%Y/%b/moodledata_%d-%b-%Y.tar.gz`
rm -rvf /backups/moodledatacopied/

Make backup of moodlesoftwere

 
#/bin/sh
mkdir -p /backups/moodlesoftwerecopied/
cp -R /srv/www/htdocs/moodle /backups/moodlesoftwerecopied/moodle/
mkdir -p /backups/moodlesoftwere/
tar -czvf /backups/moodlesoftwere/moodle.tar.gz /backups/moodlesoftwerecopied/moodle/
mkdir -p /backups/moodlesoftwere/moodlesoftwere/`/bin/date +%Y/%b`
/bin/mv /backups/moodlesoftwere/moodle.tar.gz /backups/moodlesoftwere/moodlesoftwere/`/bin/date +%Y/%b/moodle_%d-%b-%Y.tar.gz`
rm -rvf /backups/moodlesoftwerecopied/

and make backup of moodle database.

 
#/bin/sh
/usr/bin/mysqldump -uroot -p****** --opt moodle > /backups/mysql_backups/moodle/moodle.sql
/usr/bin/gzip /backups/mysql_backups/moodle/moodle.sql
mkdir -p /backups/mysql_backups/moodle/`/bin/date +%Y/%b`
/bin/mv /backups/mysql_backups/moodle/moodle.sql.gz /backups/mysql_backups/moodle/`/bin/date +%Y/%b/moodle.sql_%d-%b-%Y.gz`

These all work, and create the files in a back up directory. But once the site grows it will be to big to do full back ups daily.

How would i go about making incremental back ups of what i have?

The moodle softwere should not change that oftern.
But the moodle data will as will the mysql dump.

TIA

Matthew

How about have the system automatically delete files that are older than X days?

For example;

BACKUP_DIR="/mnt/backup"
DAYS_TO_RETAIN=30
find $BACKUP_DIR -maxdepth 1 -type f -ctime +$DAYS_TO_RETAIN -delete