If you run a server you know how important is to have a regular backup. I am sharing the script I use to back up my server.

#!/bin/bash
####################################
#
# Backup Script
#
####################################

# What to backup.
backup_files="/path/to/source /path/to/source2 /path/to/source3"

# Where to backup to.
dest="/path/to/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


# Optional: Remove backups older than a certain number of days
# find $dest -type f -mtime +7 -exec rm {} \;

# Optional: Upload backup to a remote server via SCP 
# scp $dest/$archive_file user@remote_server:/path/to/remote/directory

Explanation:

  1. backup_files: Path to the directories you want to back up, separated by a space.
  2. dest: Path to the directory where you want to store the backups.
  3. archive_file: The name of the backup file.
  4. tar czf $dest/$archive_file $backup_files: This creates a compressed source directory tarball.
Remember to replace /path/to/source and /path/to/backup with your actual source and backup directory paths.

Make sure to set the script as executable with chmod +x script_name.sh and run it with ./script_name.sh.

Keep in mind that this script is basic and might need modification depending on your specific use case, such as database backups, application-specific requirements, and security considerations. Always ensure that your backups are stored securely and regularly test your backup and restore process