Write a script that automates tar so the person executing the script always uses the desired options (cvp) and backup destination

Attachments

  • ers2.png
    ers2.png
    74.6 KB · Views: 144


This is the command I run and I got the same output the ers2 which is attached
[root@localhost tabish]# ls -l /home/tabish/.local/share/Trash/info /home/tabish/.local/share/Trash/files /home/tabish/Desktop
 
I don't get it
The problem is you have such an outdated system that the tar version on your system can't deal with filenames with spaces in it and doesn't listen to excludes. When I try it on my Fedora 35 system using tar it works with filenames with spaces in it and it works when using --exclude= to exclude a file. So the script also works on my system so the problem is with your system. I spend all day with you on this, you should reinstall your Fedora 14 system with Fedora 35 because Fedora 14 is an End of Life OS and doesn't receive anymore security updates so it shouldn't even be connected to the internet. So why are you running such an outdated system?
 
The problem is you have such an outdated system that the tar version on your system can't deal with filenames with spaces in it and doesn't listen to excludes. When I try it on my Fedora 35 system using tar it works with filenames with spaces in it and it works when using --exclude= to exclude a file. So the script also works on my system so the problem is with your system. I spend all day with you on this, you should reinstall your Fedora 14 system with Fedora 35 because Fedora 14 is an End of Life OS and doesn't receive anymore security updates so it shouldn't even be connected to the internet. So why are you running such an outdated system?

Can you please tell me which version should I install so that theses scripts could work because I have got this version from my subject teacher.The script will work in Fedora 35 right?
 
I think it's insane that your teacher is making you work with such an outdated version! Are you running a virtual machine or how are you running it?
 
You can download an iso of the latest Fedora release here, then you can use the iso to install a new vm and then you can create the users you have on your other system as well. At some point during or after the installation process it will ask you to make a user, once you are then logged into the newly installed system you can then create a new user by doing this in the terminal:
1. Create user: useradd username
2. Change user password: passwd username
 
You can download an iso of the latest Fedora release here, then you can use the iso to install a new vm and then you can create the users you have on your other system as well. At some point during or after the installation process it will ask you to make a user, once you are then logged into the newly installed system you can then create a new user by doing this in the terminal:
1. Create user: useradd username
2. Change user password: passwd username

Thank You so much for all the help
 
Glad to have helped out even though it only lead to frustration, I should have asked you from the start but didn't think you were running on such an outdated version. If you need any help during or after installation be sure to create a new topic on the forums, I do not understand why a teacher would make you use such an outdated version because it's not a smart idea to run an end of life of os and it has outdated tools. That version of Fedora has been end of life for 10 years!! Here let me show you that the script actually works on my Fedora 35 vm.
Code:
[tux@fedora bin]$ cat /etc/fedora-release
Fedora release 35 (Thirty Five)

[tux@fedora bin]$ cat backup.sh
#!/bin/bash

datapath="/home"
backuppath="/var/backup"
filename="$backuppath/$(date +%u-%a-%Y%m%d)-fullbackup.tar.gz"

if [ ! -d "$backuppath" ] ; then
mkdir "$backuppath"
fi

echo "Creating tar of location $datapath to $backuppath"
find $datapath | grep -v gvfs.* | xargs tar -cpzf $filename

if [ $? -eq 0 ]
then
   echo "Backup Finish"
else
   echo "Backup Failed"
fi

[tux@fedora bin]$ sudo ./backup.sh
Creating tar of location /home to /var/backup
tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets
Backup Finish
[tux@fedora bin]$ ls -l /var/backup/
total 28
-rw-r--r--. 1 root root 25176 Nov  3 18:38 3-Wed-20211103-fullbackup.tar.gz
 
Glad to have helped out even though it only lead to frustration, I should have asked you from the start but didn't think you were running on such an outdated version. If you need any help during or after installation be sure to create a new topic on the forums, I do not understand why a teacher would make you use such an outdated version because it's not a smart idea to run an end of life of os and it has outdated tools. That version of Fedora has been end of life for 10 years!! Here let me show you that the script actually works on my Fedora 35 vm.
Code:
[tux@fedora bin]$ cat /etc/fedora-release
Fedora release 35 (Thirty Five)

[tux@fedora bin]$ cat backup.sh
#!/bin/bash

datapath="/home"
backuppath="/var/backup"
filename="$backuppath/$(date +%u-%a-%Y%m%d)-fullbackup.tar.gz"

if [ ! -d "$backuppath" ] ; then
mkdir "$backuppath"
fi

echo "Creating tar of location $datapath to $backuppath"
find $datapath | grep -v gvfs.* | xargs tar -cpzf $filename

if [ $? -eq 0 ]
then
   echo "Backup Finish"
else
   echo "Backup Failed"
fi

[tux@fedora bin]$ sudo ./backup.sh
Creating tar of location /home to /var/backup
tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets
Backup Finish
[tux@fedora bin]$ ls -l /var/backup/
total 28
-rw-r--r--. 1 root root 25176 Nov  3 18:38 3-Wed-20211103-fullbackup.tar.gz

Thank You really appreciated it. I will let you know if any difficulties are there.
 
I pasted the wrong script, here is the script that @JasKinasis helped you out with. So you can see that it works as well.
Code:
[tux@fedora bin]$ cat /etc/fedora-release
Fedora release 35 (Thirty Five)
[tux@fedora bin]$ cat backup.sh
#!/bin/bash

datapath="/home"
backuppath="/var/backup"
filename="$backuppath/$(date +%u-%a-%Y%m%d)-fullbackup.tar.gz"

if [ ! -d "$backuppath" ] ; then
mkdir "$backuppath"
fi

echo "Creating tar of location $datapath to $backuppath"
tar -cpzf $filename $datapath

if [ $? -eq 0 ]
then
   echo "Backup Finish"
else
  echo "Backup Failed"
fi
[tux@fedora bin]$ sudo ./backup.sh
Creating tar of location /home to /var/backup
tar: Removing leading `/' from member names
Backup Finish
[tux@fedora bin]$ tar xzf /var/backup/3-Wed-20211103-fullbackup.tar.gz
[tux@fedora bin]$ ls -l /var/backup
total 20
-rw-r--r--. 1 root root 19803 Nov  3 18:50 3-Wed-20211103-fullbackup.tar.gz
[tux@fedora bin]$ ls
backup.sh  home
[tux@fedora bin]$ cat home/tux/Desktop/new\ file.txt 
Hello World
 
Blimey, this thread escalated quickly!
Just finished work and saw the notifications, ha ha!
OP was using Fedora 14(which has been end of life for 10 years!!) given to them by their teacher, the script worked on my Fedora 35 not on Fedora 14. It seems the tar version of Fedora 14 can't deal with spaces in filenames and doesn't work excluding files using --exclude= while both of those works on my Fedora 35 vm. Gvfs was in use by several users so only way to go around to prevent tar from failing was by excluding that. I should have asked in the beginning what version they were running I was assuming a more recent version I assumed wrong again. I advised them to install a Fedora 35 vm and then run the script there since that same script was already working for me 5 pages ago.
 
I pasted the wrong script, here is the script that @JasKinasis helped you out with. So you can see that it works as well.
Code:
[tux@fedora bin]$ cat /etc/fedora-release
Fedora release 35 (Thirty Five)
[tux@fedora bin]$ cat backup.sh
#!/bin/bash

datapath="/home"
backuppath="/var/backup"
filename="$backuppath/$(date +%u-%a-%Y%m%d)-fullbackup.tar.gz"

if [ ! -d "$backuppath" ] ; then
mkdir "$backuppath"
fi

echo "Creating tar of location $datapath to $backuppath"
tar -cpzf $filename $datapath

if [ $? -eq 0 ]
then
   echo "Backup Finish"
else
  echo "Backup Failed"
fi
[tux@fedora bin]$ sudo ./backup.sh
Creating tar of location /home to /var/backup
tar: Removing leading `/' from member names
Backup Finish
[tux@fedora bin]$ tar xzf /var/backup/3-Wed-20211103-fullbackup.tar.gz
[tux@fedora bin]$ ls -l /var/backup
total 20
-rw-r--r--. 1 root root 19803 Nov  3 18:50 3-Wed-20211103-fullbackup.tar.gz
[tux@fedora bin]$ ls
backup.sh  home
[tux@fedora bin]$ cat home/tux/Desktop/new\ file.txt 
Hello World

Finally.
Got the output after installing the new version
 

Attachments

  • final.png
    final.png
    8 KB · Views: 168
You can also send the output of the script to /dev/null so that it doesn't show anything except for when it finishes.
Bash:
#!/bin/bash

datapath="/home"
backuppath="/var/backup"
filename="$backuppath/$(date +%u-%a-%Y%m%d)-fullbackup.tar.gz"

if [ ! -d "$backuppath" ] ; then
mkdir "$backuppath"
fi

echo "Creating tar of location $datapath to $backuppath"
tar -cpzf $filename $datapath

if [ $? -eq 0 ]
then
   echo "Backup Finished"
else
  echo "Backup Failed"
fi
If you wanted to you could also check at the beginning of the script if you the script is being executed by a user with escalated privileges but if you are happy with this I would just leave it for that. Don't forget to thank @JasKinasis he helped out with the scripting too!
 
LOL....and here endeth the saga !!!
 

Members online


Top