Sunday, February 18, 2024

How to weekly schedule backup Sniped-it to Windows shared folder by crontab

Below is my example of scheduling weekly auto backup Snipe-it to my Windows shared folder at 23:30.

Follow the below steps.

1. Create a folder on the Linux server 

mkdir /tmp/snipeit_backup

2. Mount the Windows shared folder to the Linux folder

Shared Folder Patch: //192.168.1.6/snipeit_backup

Before mount need to install CIFS Utils pkg

sudo apt-get install cifs-utils

After installing CIFS Utils pkg, create a shell script for the mount

vi mountwinshare.sh

Copy the script below and past to the vi editor and save

#!/bin/bash
mount -t cifs -o user=youruser,password=yourpassword //192.168.1.6/snipeit_backup /tmp/snipeit_backup

3. Create the shell script for unmounting the Windows shared folder to the Linux folder

vi umountwinshare.sh

Copy the script below and past to the vi editor and save

#!/bin/bash
umount /tmp/snipeit_backup

4. Create the shell script for backup

vi snipeit_bk.sh
#!/bin/bash
php /var/www/snipe-it/artisan snipeit:backup
mv /var/www/snipe-it/storage/app/backups/*.zip /tmp/snipeit_backup

5. Schedule with Crontab

make sure the file permissions are correct, they will probably be 755, they need to be 775 for users in the Apache group to write to them.

sudo chmod 775 /var/www/snipe-it/storage/app/backup-temp/ -R
sudo chmod 775 /var/www/snipe-it/storage/app/backups/ -R

Run Crontab command

crontab -e

Copy the script below and past to the vi editor and save

25 23 * * 0 /bin/bash /mountwinshare.sh
30 23 * * 0 /bin/bash snipeit_bk.sh
40 23 * * 0 /bin/bash /umountwinshare.sh

0 comments:

Post a Comment