Skip to content

Instantly share code, notes, and snippets.

@keyle
Created September 2, 2023 03:30
Show Gist options
  • Save keyle/88dfbf3ffda8f3dda2d056a54f1f0992 to your computer and use it in GitHub Desktop.
Save keyle/88dfbf3ffda8f3dda2d056a54f1f0992 to your computer and use it in GitHub Desktop.
linux server backup script
#!/bin/bash
####################################
# Backup to tar
# inspired from
# https://ubuntu.com/server/docs/basic-backup-shell-script
####################################
# What to backup.
backup_files="/home /var/spool/mail /etc /root /opt"
# Where to backup to.
dest="/backups"
# Create archive filename.
day=$(date '+%Y-%b-%d-%H:%M')
hostname=$(hostname -s)
archive_file="backup-$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 -lach $dest
@keyle
Copy link
Author

keyle commented Sep 2, 2023

copy locally

rsync -avP username@domain:/backups ~/Documents/LinuxBackups/domain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment