-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create back-up script and daily cron job #65
Comments
Better script #!/bin/bash
# Switch to home directory
cd /home/vehu/
# Source variables
. /home/vehu/etc/env
# Delete old backups
echo "Deleting old backups..."
rm -rf backup/*
# Get date for file name
bu_date=$(date +%F)
# Make global backup directory
mkdir -p backup/g
# Backup default region
echo "Creating backup of globals..."
$gtm_dist/mupip backup -BKUPDBJNL=OFF DEFAULT backup/g
# Tar and gzip files
echo "Tarring and gzipping routines and globals..."
tar --exclude '*.o' -cf backup/$bu_date.tar ./r/
tar -rf backup/$bu_date.tar -C ./backup/ ./g
if hash pigz 2>/dev/null; then # Try pigz to speed up gzip, which is the slowest operation here
echo "Using pigz to gzip..."
pigz backup/$bu_date.tar
else
gzip backup/$bu_date.tar
fi
# Delete dat file directory
echo "Deleting gzipped globals backup..."
rm -r backup/g
# Inform the user of the backup directory and size
echo -n "Backed up to /home/vehu/backup/${bu_date}.tar.gz "
echo "Size: " $(stat --printf="%s" /home/vehu/backup/${bu_date}.tar.gz | numfmt --to=si)
# Print file path for scripts
echo /home/vehu/backup/${bu_date}.tar.gz |
that better script looks good here. the command line arg |
only other thing is maybe don't delete the old backup before the new one is taken or at least allow it to have n number on file |
Better version #!/bin/bash
# Exit on error
set -e
# Switch to home directory
cd /home/vehu/
# Source variables
. /home/vehu/etc/env
# Get date for file name
bu_date=$(date +%F)
# Remove today's backup if it exists
rm -f backup/$bu_date.tar.gz
# Make global backup directory, rm old contents just in case
mkdir -p backup/g
rm -f backup/g/*
# Backup default region and turn off journaling
echo "Creating backup of globals..."
$gtm_dist/mupip backup -BKUPDBJNL=OFF DEFAULT backup/g
# Tar and gzip files
echo "Tarring and gzipping routines and globals..."
tar --exclude '*.o' -cf backup/$bu_date.tar ./r/
tar -rf backup/$bu_date.tar -C ./backup/ ./g
if hash pigz 2>/dev/null; then # Try pigz to speed up gzip, which is the slowest operation here
echo "Using pigz to gzip..."
pigz backup/$bu_date.tar
else
gzip backup/$bu_date.tar
fi
# Delete dat file directory
echo "Deleting gzipped globals backup..."
rm -r backup/g
# Delete old backups
echo "Deleting old backups..."
mkdir backup/tmp
mv backup/$bu_date.tar.gz backup/tmp
rm -f backup/*.tar.gz
mv backup/tmp/$bu_date.tar.gz backup/
rmdir backup/tmp
# Inform the user of the backup directory and size
echo -n "Backed up to /home/vehu/backup/${bu_date}.tar.gz "
echo "Size: " $(stat --printf="%s" /home/vehu/backup/${bu_date}.tar.gz | numfmt --to=si)
# Print file path for scripts
readlink -f /home/vehu/backup/${bu_date}.tar.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a sample. Needs to be improved.
The text was updated successfully, but these errors were encountered: