<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad</title>
    <description>The latest articles on DEV Community by Mohammad (@mkhnoori).</description>
    <link>https://dev.to/mkhnoori</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1962144%2F5d734ec5-b1ea-4d5f-afa6-964bb4a302fe.png</url>
      <title>DEV Community: Mohammad</title>
      <link>https://dev.to/mkhnoori</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mkhnoori"/>
    <language>en</language>
    <item>
      <title>System Automation Using Python</title>
      <dc:creator>Mohammad</dc:creator>
      <pubDate>Thu, 05 Dec 2024 14:30:07 +0000</pubDate>
      <link>https://dev.to/mkhnoori/system-automation-using-python-o8p</link>
      <guid>https://dev.to/mkhnoori/system-automation-using-python-o8p</guid>
      <description>&lt;p&gt;automate linux config files with python&lt;br&gt;
import os&lt;br&gt;
import shutil&lt;/p&gt;

&lt;h1&gt;
  
  
  Backup Linux Config Files
&lt;/h1&gt;

&lt;p&gt;def backup_configs(configs, backup_dir):&lt;br&gt;
    os.makedirs(backup_dir, exist_ok=True)&lt;br&gt;
    for config in configs:&lt;br&gt;
        if os.path.exists(config):&lt;br&gt;
            dest = os.path.join(backup_dir, os.path.basename(config))&lt;br&gt;
            shutil.copy(config, dest)&lt;br&gt;
            print(f"Backed up {config} to {dest}")&lt;br&gt;
        else:&lt;br&gt;
            print(f"Config {config} does not exist.")&lt;/p&gt;

&lt;h1&gt;
  
  
  Example usage
&lt;/h1&gt;

&lt;p&gt;backup_configs(["/etc/hosts", "/etc/fstab"], "/backup/configs")&lt;/p&gt;

&lt;h1&gt;
  
  
  Restore Files from Backup
&lt;/h1&gt;

&lt;p&gt;def restore_configs(backup_dir, destination_dir):&lt;br&gt;
    for file in os.listdir(backup_dir):&lt;br&gt;
        src = os.path.join(backup_dir, file)&lt;br&gt;
        dest = os.path.join(destination_dir, file)&lt;br&gt;
        shutil.copy(src, dest)&lt;br&gt;
        print(f"Restored {src} to {dest}")&lt;/p&gt;

&lt;h1&gt;
  
  
  Example usage
&lt;/h1&gt;

&lt;p&gt;restore_configs("/backup/configs", "/etc")&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
