Rahul – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Tue, 17 Jan 2023 02:28:25 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 Backing Up Your Linux System with Rsync: A Step-by-Step Guide https://tecadmin.net/backup-linux-system/ https://tecadmin.net/backup-linux-system/#respond Tue, 17 Jan 2023 02:28:25 +0000 https://tecadmin.net/?p=23062 For many computer users, the most stressful part of working with a Linux system is having to back up their data. The good news is that there is a simple solution to this problem: set up an automatic rsync backup script that will automatically keep your data safe. In this article, we will go over [...]

The post Backing Up Your Linux System with Rsync: A Step-by-Step Guide appeared first on TecAdmin.

]]>
For many computer users, the most stressful part of working with a Linux system is having to back up their data. The good news is that there is a simple solution to this problem: set up an automatic rsync backup script that will automatically keep your data safe. In this article, we will go over the tools and steps that you need to take to set up an automated backup system on a Linux system with rsync. You will learn how to use rsync to automatically create backups of files, how to keep these backups up-to-date, and how to restore them in the event of data loss or corruption.

If you regularly perform backups on your Linux system, chances are you already know about rsync, a command-line utility that can be used to back up and synchronize files and directories. However, if you’re new to rsync, it might come as a surprise that this simple command is capable of backing up your entire Linux system. In this guide, we’ll show you how to use rsync to back up your Linux system using different strategies.

Steps to Backup Your Linux System

  1. Prepare a Backup Device
  2. To make a full backup of the system, you need a device that has much space to keep all files. A backup device can be a locally attached drive, network device, or cloud storage like Amazon S3, Azure Spaces, etc.

    Create a directory to store the backup on the backup device. Assuming you have attached a separate disk in your local machine mounted at /mnt directory.

    mkdir /mmnt/full-backup 
    

  3. Install Rsync Utility
  4. Rsync is a command line utility that helps to synchronize content between two directories. They either exist on the local system or one can be the remote. You can quickly install on using the default package manager on most modern Linux distributions. To install Rsync on Debian-based systems, type:

    sudo apt install rsync 
    

  5. Backup Your System
  6. You can run the command directly to make a backup of the complete system. For example, to create a backup of the system to the “/mnt/full-backup” directory, run the following command.

    sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt/full-backup 
    

    The above command will backup the entire root (/) directory, excluding /dev, /proc, /sys, /tmp, /run, /mnt, /media, and /lost+found directories, and save the data in /mnt/full-backup folder. Here:

    The `-aAXv` options are used so that the files are transferred in “archive” mode, which ensures that symbolic links, devices, permissions, ownerships, modification times, ACLs, and extended attributes are preserved.

  7. Automate the Backup
  8. It’s good practice to schedule automatic backups. You can simply add the above command in crontab, or write them in a shell script and then schedule the script.

    #!/usr/bin/evn bash
    
    BACKUP_PATH="/mnt/full-backup"
    EXCLUDE_DIR='{"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}'
    SOURCE_DIR="/"
    
    sudo rsync -aAXv ${SOURCE_DIR} --exclude=${EXCLUDE_DIR} ${BACKUP_PATH}
    
    if [ $? -eq 0 ]; then
        echo "Backup completed successfully"
    else
        echo "Some error occurred during backup"
    fi

    You can schedule the script to run automatically using a tool such as cron. This will allow you to create regular backups of your system without having to manually run the script.

    To schedule the script, edit the crontab:

    crontab -e 
    

    Append the following entry. Make sure to set the correct script name and path. The below schedule will run the script at 02 AM every day.

    0  2  *  *  *  bash backup.sh >> backup.log

    Save and close the editor.

    Conclusion

    Now that you know how to use rsync, you may want to take advantage of its advanced features. For instance, you can use rsync to efficiently copy files from one directory to another. You can also generate incremental backups that allow you to quickly recover files at any time. If you want even more control over your backup process, you can even schedule backups.

    The post Backing Up Your Linux System with Rsync: A Step-by-Step Guide appeared first on TecAdmin.

    ]]> https://tecadmin.net/backup-linux-system/feed/ 0 Sort Command in Linux with Practical Examples https://tecadmin.net/linux-sort-command/ https://tecadmin.net/linux-sort-command/#respond Mon, 16 Jan 2023 17:40:37 +0000 https://tecadmin.net/?p=33930 The `sort` command in Linux is part of the GNU Coreutils package. This command is used to sort lines of text in a specified file or from the standard input in an ascending/descending order. The sorted output can be written to a file or displayed on the standard output. The `sort` command is a simple [...]

    The post Sort Command in Linux with Practical Examples appeared first on TecAdmin.

    ]]>
    The `sort` command in Linux is part of the GNU Coreutils package. This command is used to sort lines of text in a specified file or from the standard input in an ascending/descending order. The sorted output can be written to a file or displayed on the standard output. The `sort` command is a simple and powerful tool that can be used in various scenarios, from sorting data in a file for further analysis to preparing data for a report.

    In this article, we will discuss the various options available with the `sort` command and provide some practical examples to illustrate its usage.

    The basic syntax of the `sort` command is as follows:

    # Syntax
    sort [options] [file(s)]

    This command provides various options that can be used to customize the sorting process and file(s) that need to be sorted. If no file is specified, the `sort` command will sort the input from the standard input (i.e., the keyboard).

    Here are some frequently used options with the `sort` command in Unix/Linux systems:

    • -r: sort the input in reverse order.
    • -n: sort the input numerically.
    • -k: sort the input based on a specific field or column.
    • -b: ignore the leading blanks.
    • -t: specify the field separator.
    • -u: remove duplicate lines from the output.
    • -o: specify the output file.

    Let’s take a closer look at each of these options with some examples.

    Sorting File Content

    The default content is sorted in ascending order basis on the first character. You can simply type the `sort` command followed by the file name.

    sort data.txt 
    

    You can also use the following commands to provide input to the command.

    sort < data.txt 
    cat data.txt | sort 
    

    Sorting in Reverse Order

    The -r option is used to sort the input in reverse order. Here's an example of how to use this option:

    sort -r data.txt 
    

    This command sorts the lines of text in the data.txt file in reverse order and displays the result on the screen.

    Numerical Sorting

    The -n option is used to sort the input numerically. This option is useful when sorting numbers that are represented as text. Here's an example of how to use this option:

    sort -n data.txt 
    

    This command sorts the lines of text in the data.txt file numerically and displays the result on the screen.

    Sorting by Field

    The -k option is used to sort the input based on a specific field or column. This option is useful when sorting tabular data where each line represents a record and fields are separated by a specific delimiter. The field number is specified with the option, and the fields are numbered starting from 1. Here's an example of how to use this option:

    sort -k 2 data.txt 
    

    This command sorts the lines of text in the data.txt file based on the second field (column) and displays the result on the screen.

    Specifying the Field Separator

    The -t option is used to specify the field separator when sorting by field. By default, the `sort` command assumes that the fields are separated by a space or tab character. However, this option allows you to specify a different character as the field separator. Here's an example of how to use this option:

    sort -t "," -k 2 data.txt 
    

    This command sorts the lines of text in the data.txt file based on the second field (column) and the field separator is ','. It will display the result on the screen

    Removing Duplicate Lines

    The -u option is used to remove duplicate lines from the output of the `sort` command. This option is useful when sorting a large file and you only want to keep unique lines. Here's an example of how to use this option:

    sort -u data.txt 
    

    This command sort the lines of text in the data.txt file and remove any duplicate lines from the output. The result is displayed on the screen.

    Specifying the Output File

    The -o option is used to specify the output file for the sorted data. This option is useful when saving the sorted data to a different file rather than displaying it on the screen. Here's an example of how to use this option:

    sort data.txt -o sorted_data.txt 
    

    Instead of the option, you can also use the redirect ">" operator to write content to the file.

    sort data.txt > sorted_data.txt 
    

    This command sorts the lines of text in the data.txt file and saves the result to a new file called sorted_data.txt.

    Combining Multiple Options

    You can combine different options to achieve the desired sorting result. For example, to sort a file numerically in reverse order and save the result to a new file, you can use the following command:

    sort -nr data.txt -o reverse_sorted_data.txt 
    

    You can also combine different options like this,

    sort -t "," -k 2,3 -u data.txt 
    

    This command sorts the lines of text in the "data.txt" file based on the second and third field (column) and the field separator is ',' and removes duplicate entries from the result and displays it on the screen

    Conclusion

    In conclusion, the `sort` command is a powerful and versatile tool that can be used to sort data in various scenarios. The various options available with the `sort` command allows you to customize the sorting process and achieve the desired result. With the examples and explanations provided in this article, you should have a good understanding of how to use the `sort` command and be able to apply it to your own data.

    The post Sort Command in Linux with Practical Examples appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/linux-sort-command/feed/ 0
    How to Install and Use Flask in Fedora 37/36 https://tecadmin.net/how-to-install-flask-in-fedora/ https://tecadmin.net/how-to-install-flask-in-fedora/#respond Fri, 13 Jan 2023 17:57:19 +0000 https://tecadmin.net/?p=33630 Flask is a popular microweb framework written in Python. It is lightweight and easy to use, making it a good choice for developing small web applications. It is designed to enable developers to create and scale web apps quickly and easily. It has a small and easy-to-extend core, with sensible defaults to get started quickly. [...]

    The post How to Install and Use Flask in Fedora 37/36 appeared first on TecAdmin.

    ]]>
    Flask is a popular microweb framework written in Python. It is lightweight and easy to use, making it a good choice for developing small web applications. It is designed to enable developers to create and scale web apps quickly and easily. It has a small and easy-to-extend core, with sensible defaults to get started quickly.

    In this article, we will show you how to install and use Flask on a Fedora system.

    Prerequisites

    Before you start, make sure that you have the following installed on your system:

    • Python 3: Flask is a Python web framework, so you will need to have Python installed on your system. You can check if you have Python installed by running the following command:
      python3 -V 
      

      If Python is not installed, you can install it by running the following command:

      sudo dnf install python3 
      
    • Pip: pip is the package manager for Python. It is used to install Python packages, such as Flask. You can check if you have pip installed by running the following command:
      pip3 -V 
      

      If pip is not installed, you can install it by running the following command:

      sudo dnf install python3-pip 
      

    Installing Flask on Fedora

    Once you have Python and pip installed, you can use pip to install Flask. To install Flask, run the following command:

    pip3 install Flask 
    

    This will install Flask and all of its dependencies.

    Creating a Flask App

    Now that you have Flask installed, you can create a simple Flask app. Create a file called app.py and add the following code:

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def hello():
        return 'Hello, World!'
    
    if __name__ == '__main__':
        app.run()

    This code creates a simple Flask app that displays a message when you visit the root URL.

    Run Your Flask Application

    To run the Flask app, open a terminal and navigate to the directory where you saved app.py. Then, run the following command:

    python3 app.py 
    

    This will start the Flask development server, and you should see the following output:

    Output
    * Serving Flask app 'app' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit

    To view the app, open a web browser and go to the URL http://127.0.0.1:5000/. You should see the message “Hello, World!” displayed on the page.

    Conclusion

    In this article, we showed you how to install and use Flask on a Fedora system. Flask is a lightweight and easy-to-use web framework that is perfect for developing small web applications. With Flask, you can create powerful and dynamic web applications with minimal effort.

    The post How to Install and Use Flask in Fedora 37/36 appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-flask-in-fedora/feed/ 0
    Sed Command in Linux with 15 Practical Examples https://tecadmin.net/sed-command-in-linux-with-examples/ https://tecadmin.net/sed-command-in-linux-with-examples/#respond Fri, 13 Jan 2023 10:40:35 +0000 https://tecadmin.net/?p=33461 The `sed` command is an essential tool for manipulating text in Linux. It allows you to search for patterns in a text and perform various operations on the matching text, such as replacing it, deleting it, or printing it. This command takes input from a file or standard input. The default sed command doesn’t make [...]

    The post Sed Command in Linux with 15 Practical Examples appeared first on TecAdmin.

    ]]>
    The `sed` command is an essential tool for manipulating text in Linux. It allows you to search for patterns in a text and perform various operations on the matching text, such as replacing it, deleting it, or printing it. This command takes input from a file or standard input.

    The default sed command doesn’t make changes to the original file until you used the -i command line parameter. The command alerts the text and sends the result to standard output. You can also redirect the text to the file as per the requirements.

    In this article, we’ll provide 15 practical examples of using the `sed` command to perform various tasks.

    Replace Strings Example using Sed

    1. Replace string in a file

    To replace a string in a file, you can use the 's/old_string/new_string/g' command. The syntax is:

    # Syntax
    sed 's/old_string/new_string/g' file_name

    To replace strings in a file using the sed command, use the -i argument to make the changes in-place. The command string must include the substitute command ‘s’, the original string, and the replacement string. For example, to replace all instances of the string “apple” with the string “banana” in a file called fruits.txt, use the following command:

    See the following example:

    sed 's/apple/banana/g' fruits.txt 
    

    This command reads the content from the “fruits.txt” file and replaces all occurrences of the word “apple” with the word “banana” and prints the resulting text to the terminal. The g tells the command to replace all matching occurrences globally in the file.

    You can also make the changes in the same file with the -i option.

    sed -i 's/apple/banana/g' fruits.txt 
    

    You will see that the original file is modified. You can also make s backup of file before making changes in original file.

    sed -i.bak 's/apple/banana/g' fruits.txt 
    

    A backup file of the original will be created in current directory with name fruits.txt.bak.

    2. Replace the first occurrence of each line

    To substitute only the first occurrence of a pattern on each line, you can use the s/pattern/replacement/ command. For example, to replace only the first occurrence of the word “apple” with the word “banana” in the file fruits.txt, you can use the following command:

    sed 's/apple/banana/' fruits.txt 
    

    3. Replace the last occurrence of each line

    To substitute only the last occurrence of a pattern on each line, you can use the s/pattern/replacement/g’ command. For example, to replace only the last occurrence of the word “apple” with the word “banana” in the file fruits.txt`, you can use the following command:

    sed 's/\(.*\)apple/\1banana/g' fruits.txt 
    

    4. Replace string at specific line number

    To replace a string on a specific line, you can use the lineNumbers/pattern/replacement/ command. For example, to replace the first occurrence of the word “apple” with the word “banana” on line 3 of the file fruits.txt, you can use the following command:

    sed '3s/apple/banana/' fruits.txt 
    

    5. Replace string from range of line numbers

    To replace a string on a range of lines, you can use the startLineNumber,endLineNumber/pattern/replacement/ command. For example, to replace the first occurrence of the word “apple” with the word “banana” on lines 3 through 5 of the file fruits.txt, you can use the following command:

    sed '3,5s/apple/banana/' fruits.txt 
    

    Deleting Lines in File using Sed

    6. Delete first line from file

    To delete a line that contains a certain string, you can use the /pattern/d command. For example, to delete all lines that contain the word “apple” in the file fruits.txt, you can use the following command:

    sed '1d' fruits.txt 
    

    7. Delete line contains certain string

    To delete a line that contains a certain string, you can use the '/pattern/d' command. For example, to delete all lines that contain the word “apple” in the file fruits.txt, you can use the following command:

    sed '/apple/d' fruits.txt 
    

    8. Delete lines except the matching string

    To invert the matching lines, you can use the `!` operator in combination with other commands. For example, to delete all lines that contain the word “apple” in the file fruits.txt, you can use the following command:

    sed '/apple/!d' fruits.txt 
    

    9. Delete the range of lines

    To delete a range of lines, you can use the startLineNumber,endLineNumberd command. For example, to delete lines 3 through 5 of the file fruits.txt, you can use the following command:

    sed '3,5d' fruits.txt 
    

    10. Delete empty lines from file

    You can remove the empty lines from the file using '/^$/d' option.

    sed '/^$/d' fruits.txt 
    

    This command consider a line as empty, that doesn’t contain any character, even a single space.

    Printing Lines from File using Sed

    11. Print line numbers only

    To print only the line numbers of matching lines, you can use the '/pattern/=' command. For example, to print the line numbers of all lines that contain the word “apple” in the file fruits.txt, you can use the following command:

    sed '/apple/=' fruits.txt 
    

    12. Print the range of file

    To print a range of lines, you can use the 'start,endp' commands. For example, to print the first 10 lines of the file fruits.txt, you can use the following command:

    sed -n '1,10p' fruits.txt 
    

    Inserting Lines to File using Sed

    13. Insert a new line after matching pattern

    To insert a line after a certain pattern, you can use the '/pattern/a\newline' command. For example, to insert the line “grapes” after the line that contains the word “apple” in the file fruits.txt, you can use the following command:

    sed '/apple/a\grapes' fruits.txt 
    

    14. Insert a new line before matching pattern

    To insert a line before a certain pattern, you can use the '/pattern/i\newline' command. For example, to insert the line “grapes” before the line that contains the word “apple” in the file fruits.txt, you can use the following command:

    sed '/apple/i\grapes' fruits.txt 
    

    Other Tasks using Sed

    15. Change Case of Characters

    To change the case of a string, you can use the 'y/old/new/' command. For example, to change all lowercase letters to uppercase in the file fruits.txt, you can use the following command:

    sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' fruits.txt 
    

    Conclusion

    We hope these examples have been helpful in showing you the versatility of the sed command. Remember that sed is a very powerful tool and it’s important to test your commands carefully before using them on important files. If you have any questions or need further assistance, don’t hesitate to ask. With these practical examples under your belt, you’ll be well on your way to mastering the sed command and becoming a proficient Linux administrator.

    The post Sed Command in Linux with 15 Practical Examples appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/sed-command-in-linux-with-examples/feed/ 0
    How to Print a List without Brackets in Python https://tecadmin.net/print-a-list-without-brackets-in-python/ https://tecadmin.net/print-a-list-without-brackets-in-python/#respond Thu, 12 Jan 2023 14:00:57 +0000 https://tecadmin.net/?p=33046 A Python list is an ordered and changeable collection of data objects. Unlike an array, which can contain objects of a single type, a list can contain a mixture of different types. A list in Python is used to store the sequence of various types of data. A list can be defined as a collection [...]

    The post How to Print a List without Brackets in Python appeared first on TecAdmin.

    ]]>
    A Python list is an ordered and changeable collection of data objects. Unlike an array, which can contain objects of a single type, a list can contain a mixture of different types. A list in Python is used to store the sequence of various types of data. A list can be defined as a collection of values or items of different types. Python has a great built-in list type named “list”. List literals are written within square brackets “[]”.

    Let’s initialize a Python list with the following arguments:

    my_list = [1, 2, 3, 4, 5]

    By default, when you print a list in Python, it is displayed with square brackets and commas separating the items. For example:

    print(my_list)
    # Output: [1, 2, 3, 4, 5]

    If you want to print a list without the brackets and commas, you can use one of the following methods:

    Method 1: Using for loop

    You can use a loop to iterate through the items in the list and print them one by one, without the brackets and commas. Here is an example of how to do this:

    for item in my_list:
        print(item, end=' ')
    # Output: 1 2 3 4 5

    In this example, we use a for loop to iterate through the items in the list. For each item, we use the print() function to print it, followed by a space (end=’ ‘). This will print each item on the same line, separated by a space.

    Method 2: Using the join() method

    You can also use the join() method to join the items in the list into a single string, separated by a space. Then, you can use the print() function to print the string without the brackets. Here is an example of how to do this:

    string = ' '.join(map(str, my_list))
    print(string)
    # Output: 1 2 3 4 5

    In this example, we use the join() method to join the items in the list into a single string, separated by a space. The map() function is used to convert the items in the list to strings (since join() can only join strings). Finally, we use the print() function to print the string.

    Method 3: Using the `*` operator

    You can also use the * operator to unpack the items in the list and pass them as separate arguments to the print() function. This will print each item on the same line, separated by a space. Here is an example of how to do this:

    print(*my_list)
    # Output: 1 2 3 4 5

    In this example, we use the “*” operator to unpack the items in the list and pass them as separate arguments to the print() function. The “*” operator tells Python to treat the items in the list as separate arguments, rather than as a single list.

    Conclusion

    In this article, we have covered three different methods for printing a list without brackets in Python: using a loop, using the join() method, and using the “*” operator. Each of these methods has its own advantages and disadvantages, and the best method to use will depend on your specific needs.

    The post How to Print a List without Brackets in Python appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/print-a-list-without-brackets-in-python/feed/ 0
    How to Install Google Chrome in Pop!_OS https://tecadmin.net/how-to-install-google-chrome-in-popos/ https://tecadmin.net/how-to-install-google-chrome-in-popos/#respond Thu, 12 Jan 2023 13:43:14 +0000 https://tecadmin.net/?p=33368 Google Chrome is a popular web browser that is widely used for browsing the internet, streaming videos, and running web-based applications. If you want to install Google Chrome on Pop!_OS, you can follow a few simple steps to download and install the browser. In this article, we will walk through the process of installing Google [...]

    The post How to Install Google Chrome in Pop!_OS appeared first on TecAdmin.

    ]]>
    Google Chrome is a popular web browser that is widely used for browsing the internet, streaming videos, and running web-based applications. If you want to install Google Chrome on Pop!_OS, you can follow a few simple steps to download and install the browser. In this article, we will walk through the process of installing Google Chrome on Pop!_OS, including downloading the installation package, installing dependencies, making the package executable, and using the “dpkg” command to install the package.

    Steps to Install Google Chrome on Pop!_OS

    1. Download the Google Chrome package:
    2. Go to the Google Chrome website (https://www.google.com/chrome/) and click on the “Download Chrome” button. This will download the installation package for the latest version of Google Chrome.

      You can also download the latest Google Chrome version directly from the terminal with the following command:

      wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 
      

      The above command will download “google-chrome-stable_current_amd64.deb” in the current directory.

    3. Install the necessary dependencies:
    4. Google Chrome requires several dependencies to be installed on your system in order to run. To install these dependencies, you can use the following command:

      sudo apt install libappindicator3-1 libgbm1 libindicator3-7 libu2f-udev
      

    5. Install Google Chrome:
    6. To install Google Chrome, you can use the “dpkg” command, which is a package manager for .deb packages. Run the following command:

      sudo dpkg -i google-chrome-stable_current_amd64.deb 
      

      This will install the Google Chrome web browser and its dependencies on your Pop!_OS system.

    7. Launch Google Chrome:
    8. To launch Google Chrome, you can use the `google-chrome` command in the terminal, or you can search for “Google Chrome” in the Pop!_OS menu and click on the icon to open the browser.

      Installing Google Chrome on Pop!_OS
      Installing Google Chrome on Pop!_OS

    Conclusion

    Installing Google Chrome on Pop!_OS is a straightforward process that involves downloading the installation package from the Google Chrome website, installing the necessary dependencies, making the package executable, and using the “dpkg” command to install the package. Once Google Chrome is installed, you can launch it from the terminal or the Pop!_OS menu. With Google Chrome installed, you can enjoy all of the features and benefits of this popular web browser on your Pop!_OS system.

    The post How to Install Google Chrome in Pop!_OS appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-install-google-chrome-in-popos/feed/ 0
    Rsync Command to Exclude Files and Directories: An Ultimate Guide https://tecadmin.net/how-to-exclude-files-and-directories-using-rsync-examples/ https://tecadmin.net/how-to-exclude-files-and-directories-using-rsync-examples/#respond Wed, 11 Jan 2023 02:36:56 +0000 https://tecadmin.net/?p=33945 Rsync is a powerful command-line utility for Unix/Linux systems, that allows you to synchronize and transfer files between different two systems. One of the key features of Rsync is the ability to exclude files and directories from the synchronization process. This feature can be incredibly useful for a variety of tasks, such as backups, codebase [...]

    The post Rsync Command to Exclude Files and Directories: An Ultimate Guide appeared first on TecAdmin.

    ]]>
    Rsync is a powerful command-line utility for Unix/Linux systems, that allows you to synchronize and transfer files between different two systems. One of the key features of Rsync is the ability to exclude files and directories from the synchronization process. This feature can be incredibly useful for a variety of tasks, such as backups, codebase synchronization, and data management.

    In this article, we’ll get a basic understating of excluding files and directories with Rsync command line utility. Also includes a few useful examples using this feature.

    Exclude files and directories with rsync

    The most basic method for excluding files and directories with Rsync is by using the --exclude option followed by the name of the file or directory you want to exclude. For example, if you want to exclude all files with the “.log” extension, you can use the following command:

    rsync -av --exclude='*.log' source/ destination/ 
    

    You can also exclude specific directories by including the entire path, like this:

    rsync -av --exclude='path/to/directory' source/ destination/ 
    

    Exclude all written in text file

    Another way to exclude files and directories is by using a separate file called an “exclude file”. This file contains a list of excluded patterns, one per line, and Rsync will read the file and apply all the patterns specified in it.

    rsync -av --exclude-from='exclude.txt' source/ destination/ 
    

    Here `exclude.txt` file containing all the patterns of files or directories to be excluded

    The patterns in the exclude file can be a shell glob (e.g., *.log) or a regular expression (if the --exclude-from option is replaced with --exclude-from-file).

    You can also use a `.gitignore` file to specify files to be excluded, which is a good way to exclude version control files.

    rsync -av --exclude-from='.gitignore' source/ destination/ 
    

    Include specific files and exclude other

    It is also possible to include and exclude files at the same time by using the --include option followed by the name of the file or directory you want to include, and the --exclude option for everything else. For example, the following command will include all files with the “.txt” extension and exclude all other files:

    rsync -av --include='*.txt' --exclude='*' source/ destination/ 
    

    It’s important to note that the order of the --include and --exclude options is significant. If you want to include a specific file or directory and then exclude others, the --include option should come first.

    Exclude existing files on destination

    Another thing to consider is to exclude files that are already present in the destination and the destination is a backup. You can use --ignore-existing options to achieve this.

    rsync --ignore-existing -av source/ destination/ 
    

    You can read more about it: https://tecadmin.net/rsync-command-to-copy-missing-files-only/

    Exclude large files

    Another consideration when using Rsync to exclude files and directories is performance. Excluding large files or directories can save a significant amount of time and space when transferring or synchronizing data. For example, if you’re performing a backup, you may want to exclude large media files or backups of backups.

    rsync --ignore-existing --size-range='+100M' -av source/ destination/
    

    There are also many other options available with rsync that can be used to further fine-tune the file transfer process. For example, you can use the --exclude option to exclude certain files or directories from the transfer, or the --dry-run option to see what files would be copied without actually performing the transfer.

    Wrap Up

    Overall, the ability to exclude files and directories with Rsync is a powerful and essential feature that can greatly improve the efficiency, accuracy, and security of your backups, synchronization, and data management tasks. By using the methods and best practices discussed in this article, you can take full advantage of this feature and ensure that your Rsync commands are working as efficiently and effectively as possible.

    The post Rsync Command to Exclude Files and Directories: An Ultimate Guide appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/how-to-exclude-files-and-directories-using-rsync-examples/feed/ 0
    Rsync Command to Copy Missing Files (Examples) https://tecadmin.net/rsync-command-to-copy-missing-files-only/ https://tecadmin.net/rsync-command-to-copy-missing-files-only/#respond Wed, 11 Jan 2023 01:51:32 +0000 https://tecadmin.net/?p=33935 Rsync is a command-line utility that is used to synchronize files and directories between two locations. It is commonly used to copy files from one location to another while preserving file attributes such as permissions, timestamps, and ownership. One of the powerful features of rsync is the ability to copy only the files that are [...]

    The post Rsync Command to Copy Missing Files (Examples) appeared first on TecAdmin.

    ]]>
    Rsync is a command-line utility that is used to synchronize files and directories between two locations. It is commonly used to copy files from one location to another while preserving file attributes such as permissions, timestamps, and ownership. One of the powerful features of rsync is the ability to copy only the files that are missing or have been modified in the destination location. This can be useful when you want to keep a backup of your files, or when you want to update a website or server with the latest changes.

    Copy Missing Files with Rsync

    To copy only missing files using rsync, you can use the `--ignore-existing` option. This tells rsync to skip files that already exist in the destination location and only copy files that are missing. For example, to copy all files from the directory “source” to the directory “destination”, using the `--ignore-existing` option, you would run the following command:

    rsync --ignore-existing -av source/ destination/ 
    

    The -a option tells rsync to preserve file attributes and the -v option verbose mode which will show you the progress of the transfer and the files that are being copied.

    Copy Modified Files with Rsync

    It’s also possible to copy only the new or modified files and exclude the older files that already exist in the destination. For this you can use -u or --update along with -r or --recursive option to transfer the directory recursively.

    rsync -ur source/ destination/ 
    

    Copy Files Modified in Last N Days

    You can also specify that the rsync should only copy files that have been modified in the last N days. For example, to copy only files that have been modified in the last 7 days, you would use the --max-age option along with the number of days, like this:

    rsync --ignore-existing --max-age=7 -av source/ destination/
    

    Copy Files By Size with Rsync

    It’s also possible to specify only to copy the files that are larger or smaller than a certain size using --size-range option, which takes the argument of either +SIZE or -SIZE. For example, if you want to copy only files that are larger than 100MB, you would use the --size-range option like this:

    rsync --ignore-existing --size-range='+100M' -av source/ destination/
    

    There are also many other options available with rsync that can be used to further fine-tune the file transfer process. For example, you can use the --exclude option to exclude certain files or directories from the transfer, or the --dry-run option to see what files would be copied without actually performing the transfer.

    Conclusion

    In conclusion, the rsync command is a powerful tool for copying files and directories and can be used to copy only the files that are missing or have been modified in the destination location. By using the various options available with rsync, you can further fine-tune the file transfer process to suit your specific needs.

    The post Rsync Command to Copy Missing Files (Examples) appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/rsync-command-to-copy-missing-files-only/feed/ 0
    lsusb Command in Linux (Display USB device Details) https://tecadmin.net/lsusb-command-in-linux/ https://tecadmin.net/lsusb-command-in-linux/#respond Tue, 10 Jan 2023 07:12:55 +0000 https://tecadmin.net/?p=33880 The `lsusb` command is a utility in Linux that allows users to list the USB (Universal Serial Bus) devices connected to the system. This utility is the part of “usbutils” package, which provides utilities to display information about USB buses in the system and the devices connected to them. A USB (Universal Serial Bus) is [...]

    The post lsusb Command in Linux (Display USB device Details) appeared first on TecAdmin.

    ]]>
    The `lsusb` command is a utility in Linux that allows users to list the USB (Universal Serial Bus) devices connected to the system. This utility is the part of “usbutils” package, which provides utilities to display information about USB buses in the system and the devices connected to them.

    A USB (Universal Serial Bus) is a widely used standard for connecting devices to computers. It allows users to connect a many of devices such as keyboards, mice, printers, and external storage devices to their computers with ease. The `lsusb` command can be used to display information about these devices, including their vendor and product ID, device name, device driver, and others.

    In this article, we will discuss the syntax and options of the lsusb command, and provide examples of how to use it to list and display information about USB devices in Linux.

    Syntax

    The basic syntax of the lsusb command is:

    lsusb [options]

    Options

    Some common options used with the lsusb command are:

    • -v: Display detailed information about the USB devices.
    • -t: Display a tree-like view of the USB devices.
    • -s: Display information about a specific USB device, specified by its bus and device number.
    • -d: Display information about a specific USB device, specified by its vendor and product ID.
    • -D: Selects which device will be examined.

    Examples

    1. To list all the USB devices connected to the system, use the lsusb command without any options:
      lsusb 
      
      Output
      Bus 002 Device 004: ID 046d:0a37 Logitech, Inc. USB Headset H540 Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 413c:301a Dell Computer Corp. Bus 001 Device 003: ID c0f4:05e0 Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    2. To display detailed information about the USB devices, use the -v option:
      lsusb -v 
      
    3. To display a tree-like view of the USB devices, use the -t option:
      lsusb -t 
      
      Output
      /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M |__ Port 1: Dev 4, If 0, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 1: Dev 4, If 1, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 1: Dev 4, If 2, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 1: Dev 4, If 3, Class=Human Interface Device, Driver=usbhid, 12M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 1: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 1: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 2: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
    4. To display information about a specific USB device, use the -s option followed by the bus and device number. For example, to display information about the USB device on bus 2 and device 4, use the following command:
      lsusb -s 2:4 -v 
      
      Output
      Bus 002 Device 004: ID 046d:0a37 Logitech, Inc. USB Headset H540 Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x046d Logitech, Inc. idProduct 0x0a37 USB Headset H540 bcdDevice 1.22 iManufacturer 1 iProduct 2 iSerial 3 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 0x011c
    5. To display information about a specific USB device, use the -d option followed by the vendor and product ID. For example, to display information about a device with vendor ID 8087 and product ID c52b, use the following command:
      lsusb -d 1d6b:0002 -v 
      
      Output
      Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 9 Hub bDeviceSubClass 0 bDeviceProtocol 0 Full speed (or root) hub bMaxPacketSize0 64 idVendor 0x1d6b Linux Foundation idProduct 0x0002 2.0 root hub bcdDevice 5.15 iManufacturer 3 iProduct 2 iSerial 1

    Using the lsusb Command with Other Utilities

    The lsusb command can be used in combination with other utilities to perform a variety of tasks.

    1. Find the Vendor and Product ID of a USB Device
    2. To find the vendor and product ID of a USB device, use the lsusb command with the -v option and grep for the idVendor and idProduct fields:

      lsusb -v | grep -E 'idVendor|idProduct'
      
      Output
      idVendor 0x046d Logitech, Inc. idProduct 0x0a37 USB Headset H540 idVendor 0x8087 Intel Corp. idProduct 0x0024 Integrated Rate Matching Hub idVendor 0x8087 Intel Corp. idProduct 0x0024 Integrated Rate Matching Hub idVendor 0x1d6b Linux Foundation idProduct 0x0002 2.0 root hub

    3. Find the Device Name of a USB Device
    4. To find the device name of a USB device, use the lsusb command with the -v option and grep for the iProduct field:

      lsusb -v | grep iProduct
      
      Output
      iProduct 2 Logitech USB Headset H540 iProduct 2 EHCI Host Controller iProduct 2 Dell MS116 USB Optical Mouse iProduct 2 usb keyboard

    5. Find the Device Driver of a USB Device
    6. To find the device driver of a USB device, use the lsusb command with the -t option and grep for the device name:

      lsusb -t | grep Unifying
      
      Output
      |__ Port 2: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M

      In this example, the device driver for the USB device is “usbhid”.

    7. Find the Device Node of a USB Device
    8. To find the device node of a USB device, use the lsusb command with the -t option and look for the device name in the /dev directory:

      lsusb -t
      

      Now execute:

      ls /dev/input/
      
      Output
      by-id event0 event10 event2 event4 event6 event8 mice by-path event1 event11 event3 event5 event7 event9 mouse0

      In this example, the device node for the USB device is /dev/input/mouse0.

    Conclusion

    In this article, you have learned about the `lsusb` command line utility and how to use it to list and display information about USB devices connected to a Linux system. We also saw how to use the lsusb command with other utilities to perform various tasks related to USB devices.

    The post lsusb Command in Linux (Display USB device Details) appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/lsusb-command-in-linux/feed/ 0
    (Resolved) MySQL connection error: certificate verify failed https://tecadmin.net/mysql-connection-error-certificate-verify-failed/ https://tecadmin.net/mysql-connection-error-certificate-verify-failed/#respond Tue, 10 Jan 2023 03:00:35 +0000 https://tecadmin.net/?p=33812 The SSL connection error: error:0A000086:SSL routines::certificate verify failed error is usually encountered when establishing an SSL connection to a MySQL server. I was configuring the replication between two MySQL servers running with MySQL version 8.0. After configuring the replication, the “SHOW SLAVE STATUS” command on the slave instance shows me the following error: Last_IO_Error: error [...]

    The post (Resolved) MySQL connection error: certificate verify failed appeared first on TecAdmin.

    ]]>
    The SSL connection error: error:0A000086:SSL routines::certificate verify failed error is usually encountered when establishing an SSL connection to a MySQL server. I was configuring the replication between two MySQL servers running with MySQL version 8.0. After configuring the replication, the “SHOW SLAVE STATUS” command on the slave instance shows me the following error:

    Last_IO_Error: error connecting to master ‘repl@107.189.159.252:3306’ – retry-time: 60 retries: 3 message: SSL connection error: error:0A000086:SSL routines::certificate verify failed

    Then I tried to connect the Master server from the slave using the command line, with the client certificate. Again I received the following error with the connection:

    mysql -h 192.168.1.100 -u repl_user -p --ssl-ca=/etc/mysql/certs/ca.pem --ssl-cert=/etc/mysql/certs/client-cert.pem --ssl-key=/etc/mysql/certs/client-key.pem 
    
    Output
    Enter password: ERROR 2026 (HY000): SSL connection error: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

    Possible Causes

    This error can be occurred due to several reasons. Here are some possible causes:

    • The MySQL server’s SSL certificate is not trusted by the client because it is self-signed or not signed by a certificate authority (CA) that is trusted by the client.
    • The MySQL server’s SSL certificate has expired.
    • The MySQL server’s SSL certificate is not properly configured.
    • The client is using an old version of the MySQL client library that does not support the server’s SSL certificate.

    Solution

    1. Check if both system clocks are synchronized.
    2. Next verify the client and server certificate with the CA file and make sure everything is OK. Use the following command to verify the certificates:
      openssl verify -CAfile ca-cert.pem server-cert.pem client-cert.pem 
      
      server-cert.pem: OK
      client-cert.pem: OK
      
    3. Make sure to set a different “Common Name (FQDN)” for the CA certificate and the master/client certificate.
    4. Check the state of the SSL/TLS variables by typing. Make sure the correct certificate is used by the server.
      SHOW VARIABLES LIKE '%ssl%'; 
      
      Output
      +-------------------------------------+----------------------------------+ | have_openssl | YES | | have_ssl | YES | | ssl_ca | /etc/mysql/certs/ca-cert.pem | | ssl_capath | | | ssl_cert | /etc/mysql/certs/server-cert.pem | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_fips_mode | OFF | | ssl_key | /etc/mysql/certs/server-key.pem | | ssl_session_cache_mode | ON | | ssl_session_cache_timeout | 300 | +-------------------------------------+----------------------------------+ 27 rows in set (0.01 sec)
    5. Finally make sure that you are using the correct database username, hostname, and password to connect.

    Conclusion

    In conclusion, the `SSL connection error: error:0A000086:SSL routines::certificate verify failed error` can occur when establishing an SSL connection to a MySQL server for several reasons, including an untrusted or expired SSL certificate, a misconfigured SSL certificate, or an outdated MySQL client library. To resolve this error, you can import the server’s SSL certificate into the client’s trust store, renew the SSL certificate, check the server’s SSL configuration, or upgrade the MySQL client library to a newer version that supports the server’s SSL certificate.

    The post (Resolved) MySQL connection error: certificate verify failed appeared first on TecAdmin.

    ]]>
    https://tecadmin.net/mysql-connection-error-certificate-verify-failed/feed/ 0