Automated Backup Bash Script.
- Setting up the Backup Script:
- create a directory for the script and place it there.
- set up "source directory" and "destination directory".
- make the script executable:
chmod u+x script.sh
- Create a Group:
- use the groupadd command to create a new group named "backupusers":
sudo groupadd backupusers**
- use the groupadd command to create a new group named "backupusers":
- Configure Group Permissions:
- change the ownership of the script to the new group:
chown :backupusers script.sh
- allow the group to execute the scrip:
chmod g+x script.sh
- change the ownership of the script to the new group:
- Create a User:
- use the useradd command to create a new user named "backupuser":
sudo useradd -m -G backupusers backupuser
- add new user to the group:
sudo usermod -a -G backupusers backupuser
- Set a password for the new user:
sudo passwd backupuser
- use the useradd command to create a new user named "backupuser":
- Schedule the Backup Script to run automatically with a Cron Job:
- open the crontab for the "backupuser":
sudo crontab -u backupuser -e
- schedule the backup script to run daily at 12:00 PM :
0 12 * * * /path/to/script.sh
- open the crontab for the "backupuser":
- Testing:
- manually testing the script to ensure it works:
sudo -u backupuser /path/to/script.sh
- manually testing the script to ensure it works: