Skip to content

Instantly share code, notes, and snippets.

@silviaclaire
Created May 23, 2018 06:34
Show Gist options
  • Save silviaclaire/fa932724d099ab5279cb4cb1a0a557a8 to your computer and use it in GitHub Desktop.
Save silviaclaire/fa932724d099ab5279cb4cb1a0a557a8 to your computer and use it in GitHub Desktop.
Linux: Create backup on a remotely mounted NFS file system.
#!/bin/bash
####################################
#
# Backup to NFS mount
# https://help.ubuntu.com/lts/serverguide/backup-shellscripts.html.en
#
####################################
# What to backup.
backup_files="/home /var/spool/mail /etc /root /boot /opt"
# Where to backup to.
dest="/mnt/backup"
# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
# Print end status message.
echo
echo "Backup finished"
date
# Long listing of files in $dest to check file sizes.
ls -lh $dest
# To see a listing of the archive contents
tar -tzvf /mnt/backup/host-Monday.tgz
# To restore a file from the archive to a different directory
tar -xzvf /mnt/backup/host-Monday.tgz -C /tmp etc/hosts
# To restore all files in the archive
# !This will overwrite the files currently on the file system.
cd /
sudo tar -xzvf /mnt/backup/host-Monday.tgz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment