Skip to content

Instantly share code, notes, and snippets.

@kendrickjr
Created September 1, 2022 10:43
Show Gist options
  • Save kendrickjr/55f5f618ca62c3fd716516183181c209 to your computer and use it in GitHub Desktop.
Save kendrickjr/55f5f618ca62c3fd716516183181c209 to your computer and use it in GitHub Desktop.
BackupScript for Dspace ()
This is the Origional Copy From Gibson (R.I.P)
Create local backup script
Here is a sample script to make local backups which are then sent to the remote backup server.
Type the following.
sudo nano /usr/local/bin/backup.sh
Now copy and paste the following into the open editor and modify the backup variables to suit your location and server.
Replace %hostname% with the hostname of your server.
Replace %email-address% with the email address of the person responsible for server backups.
#!/bin/bash
# Setup shell to use for backups
SHELL=/bin/bash
# Setup name of local server to be backed up
SERVER="%hostname%"
# Setup event stamps
DOW=`date +%a`
TIME=`date`
# Setup paths
FOLDER="/home/backup"
FILE="/var/log/backup-$DOW.log"
# Do the backups
{
echo "Backup started: $TIME"
# Make the backup folder if it does not exist
if test ! -d /home/backup
then
mkdir -p /home/backup
echo "New backup folder created"
else
echo ""
fi
# Make sure we're in / since backups are relative to that
cd /
# Get a list of the installed software
dpkg --get-selections > $FOLDER/installed-software-$DOW.txt
## PostgreSQL database (Needs a /root/.pgpass file)
which -a psql
if [ $? == 0 ] ; then
echo "SQL dump of PostgreSQL databases"
su - postgres -c "pg_dump --inserts dspace > /tmp/dspace-db.sql"
cp /tmp/dspace-db.sql $FOLDER/dspace-db-$DOW.sql
su - postgres -c "vacuumdb --analyze dspace > /dev/null 2>&1"
fi
# Backup MySQL database (Needs a /root/.my.cnf file)
which -a mysql
if [ $? == 0 ] ; then
echo "SQL dump of MySQL databases"
mysqldump -A > $FOLDER/mysql-db-$DOW.sql
fi
# Backup '/etc' folder
echo "Archive '/etc' folder"
tar czf $FOLDER/etc-$DOW.tgz etc/
# Backup '/root' folder
echo "Archive '/root' folder"
tar czf $FOLDER/root.tgz root/
# Backup '/usr/local' folder
echo "Archive '/usr/local' folder"
tar czf $FOLDER/usr-local.tgz usr/local/
# View backup folder
echo ""
echo "** Backup folder **"
ls -lhS $FOLDER
# Show disk usage
echo ""
echo "** Disk usage **"
df -h
TIME=`date`
echo "Backup ended: $TIME"
} > $FILE
# Prepare email
cat $FILE | mail -s "BACKUP : $DOW : $SERVER" %email-address%
### EOF ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment