Contacts & links

Designer

Name days

Today:
Tomorrow:

Weather

Počasí Hradec Králové - Slunečno.cz

Other

Actual date:

Linux Debian scripts for permissions change and folder backup

I was looking for such scripts for long a time, but with various results. Finally, I wrote the following working scripts, which I am using for files transfer from PC to web server and back via file server and for backup of various folders.

Script for setting permissions for web server without influencing *.sh files (scripts itself):

#! /bin/sh
sudo chmod 660 -R $(ls --ignore='*.sh')
sudo chown www-data:www-data -R $(ls --ignore='*.sh')

Just copy this text to a file with a name for example "Permissions2Server.sh", change the name of user permissions eventually and run from bash.

Script for setting permissions for transferring back to PC without influencing *.sh files (scripts itself):

#! /bin/sh
sudo chmod 777 -R $(ls --ignore='*.sh')
sudo chown user:user -R $(ls --ignore='*.sh')

again, just copy this text to a file with appropriate name, for example "Permissions2PC.sh", change user name and run from bash.

And finally, script for backup of the whole folder to compressed file somewhere on the disk:

#!/bin/bash
#Purpose = Backup of folder to the file with name YYYYMMDD-FileName
DATE=$(date +"%Y%m%d")
SRCDIR="/home/foldername01/foldername02"
DESDIR="/home/foldername03/foldername04"
FILENAME=$DATE-filename.tar.gz
# Making backup with compress
tar -cpzf $DESDIR/$FILENAME $SRCDIR

and again, just copy this text to a file with a name for example "BackUpFolder.sh", change folders names, filename and run from bash.