Writing a bash script
I need some help writing a bash script to backup files from my system and put them into a compressed folder.
I would like to integrate cron with this as well file1=/home/user/etc using tar -czf Basically, I have a folder on my desktop that I would like to have backed up and archived on a schedule or whenever the files within it change. Any help on how to execute this? |
@ Reply
Hi Leroy1990,
Welcome to LQ!!! Here is how your script should go: 1. It should create an archive using tar -cvf say: tar -cvf foldter.tar.gz folder_name 2. Script should look for folder.tar.gz. If it already exist then does not create a new one just echo that folder existing and continue with the next step. 3. If folder.tar.gz exist then you can append to it using tar -rf folder.tar.gz folder_name It will be good if you would have pasted the script that you have already prepared. |
Quote:
My bash script will be structured as follows, Code:
#! /bin/bash |
@ Reply
Alright. Here is how it should look like:
Code:
#!/bin/bash I would also recommend you to go through these links which will help you with bash scripting: http://tldp.org/LDP/abs/abs-guide.pdf http://tldp.org/LDP/Bash-Beginners-G...ners-Guide.pdf |
Here's a stylistic alternative, with the same functionality as T3RM1NVT0R's script:
Code:
#!/bin/bash |
Quote:
Code:
backup1.sh: line 10: syntax error in conditional expression |
@ Reply
Put the double quotes as:
Code:
if [[ -e "$archive" ]]; then # Use a file existence test rather than the ls return code |
All times are GMT -5. The time now is 07:03 AM. |